Add Lawnfeed support (#2095)
This commit is contained in:
24 files changed
+1147
-2
No files matched your search
+1
-1
@@ -43,7 +43,7 @@
|
||||
attributes and intent filters the same
|
||||
-->
|
||||
<activity
|
||||
android:name="com.android.launcher3.Launcher"
|
||||
android:name="ch.deletescape.lawnchair.LawnchairLauncher"
|
||||
android:launchMode="singleTask"
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:stateNotNeeded="true"
|
||||
|
||||
@@ -189,6 +189,7 @@ android {
|
||||
|
||||
lawn {
|
||||
java.srcDirs = ['src_flags', 'src_shortcuts_overrides', 'lawnchair/src']
|
||||
aidl.srcDirs = ['lawnchair/aidl']
|
||||
res.srcDirs = ['lawnchair/res']
|
||||
manifest.srcFile "lawnchair/AndroidManifest.xml"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package amirz.aidlbridge;
|
||||
|
||||
import amirz.aidlbridge.IBridgeCallback;
|
||||
|
||||
interface IBridge {
|
||||
oneway void bindService(in IBridgeCallback cb, in int flags);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package amirz.aidlbridge;
|
||||
|
||||
interface IBridgeCallback {
|
||||
oneway void onServiceConnected(in ComponentName name, in IBinder service);
|
||||
|
||||
oneway void onServiceDisconnected(in ComponentName name);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import com.google.android.libraries.launcherclient.ILauncherOverlayCallback;
|
||||
|
||||
interface ILauncherOverlay {
|
||||
|
||||
oneway void startScroll();
|
||||
|
||||
oneway void onScroll(in float progress);
|
||||
|
||||
oneway void endScroll();
|
||||
|
||||
oneway void windowAttached(in LayoutParams lp, in ILauncherOverlayCallback cb, in int flags);
|
||||
|
||||
oneway void windowDetached(in boolean isChangingConfigurations);
|
||||
|
||||
oneway void closeOverlay(in int flags);
|
||||
|
||||
oneway void onPause();
|
||||
|
||||
oneway void onResume();
|
||||
|
||||
oneway void openOverlay(in int flags);
|
||||
|
||||
oneway void requestVoiceDetection(in boolean start);
|
||||
|
||||
String getVoiceSearchLanguage();
|
||||
|
||||
boolean isVoiceDetectionRunning();
|
||||
|
||||
boolean hasOverlayContent();
|
||||
|
||||
oneway void windowAttached2(in Bundle bundle, in ILauncherOverlayCallback cb);
|
||||
|
||||
oneway void unusedMethod();
|
||||
|
||||
oneway void setActivityState(in int flags);
|
||||
|
||||
boolean startSearch(in byte[] data, in Bundle bundle);
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
interface ILauncherOverlayCallback {
|
||||
|
||||
oneway void overlayScrollChanged(float progress);
|
||||
|
||||
oneway void overlayStatusChanged(int status);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="bridge_signature_hash">0xB662CC2F</integer>
|
||||
<string name="bridge_version" translatable="false">v3</string>
|
||||
<integer name="lawnfeed_signature_hash">0x7F7A957A</integer>
|
||||
</resources>
|
||||
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* This file is part of Lawnchair Launcher.
|
||||
*
|
||||
* Lawnchair Launcher is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Lawnchair Launcher is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Lawnchair Launcher. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ch.deletescape.lawnchair
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.ApplicationInfo.FLAG_SYSTEM
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.Uri
|
||||
import android.os.Process
|
||||
import android.util.Log
|
||||
import ch.deletescape.lawnchair.util.SingletonHolder
|
||||
import ch.deletescape.lawnchair.util.preferences.LawnchairPreferences
|
||||
import com.android.launcher3.BuildConfig
|
||||
import com.android.launcher3.R
|
||||
import com.android.launcher3.Utilities
|
||||
|
||||
class FeedBridge(private val context: Context) {
|
||||
|
||||
private val shouldUseFeed = context.applicationInfo.flags and FLAG_SYSTEM == 0
|
||||
private val prefs = LawnchairPreferences.getInstance(context)
|
||||
private val bridgePackages by lazy {
|
||||
listOf(
|
||||
PixelBridgeInfo("com.google.android.apps.nexuslauncher", R.integer.bridge_signature_hash),
|
||||
BridgeInfo("ch.deletescape.lawnchair.lawnfeed", R.integer.lawnfeed_signature_hash)
|
||||
)
|
||||
}
|
||||
|
||||
fun resolveBridge(): BridgeInfo? {
|
||||
val customBridge = customBridgeOrNull()
|
||||
return when {
|
||||
customBridge != null -> customBridge
|
||||
!shouldUseFeed -> null
|
||||
else -> bridgePackages.firstOrNull { it.isAvailable() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun customBridgeOrNull() = if (prefs!!.getString(LawnchairPreferences.FEED_PROVIDER, "")!!.isNotBlank()) {
|
||||
val bridge = CustomBridgeInfo(prefs.getString(LawnchairPreferences.FEED_PROVIDER, "")!!)
|
||||
if (bridge.isAvailable()) bridge else null
|
||||
} else null
|
||||
|
||||
private fun customBridgeAvailable() = customBridgeOrNull()?.isAvailable() == true
|
||||
|
||||
fun isInstalled(): Boolean {
|
||||
return customBridgeAvailable() || !shouldUseFeed || bridgePackages.any { it.isAvailable() }
|
||||
}
|
||||
|
||||
fun resolveSmartspace(): String {
|
||||
return bridgePackages.firstOrNull { it.supportsSmartspace }?.packageName
|
||||
?: "com.google.android.googlequicksearchbox"
|
||||
}
|
||||
|
||||
open inner class BridgeInfo(val packageName: String, signatureHashRes: Int) {
|
||||
protected open val signatureHash = if (signatureHashRes > 0) context.resources.getInteger(signatureHashRes) else 0
|
||||
|
||||
open val supportsSmartspace = false
|
||||
|
||||
fun isAvailable(): Boolean {
|
||||
val info = context.packageManager.resolveService(
|
||||
Intent(overlayAction)
|
||||
.setPackage(packageName)
|
||||
.setData(
|
||||
Uri.parse(
|
||||
StringBuilder(packageName.length + 18)
|
||||
.append("app://")
|
||||
.append(packageName)
|
||||
.append(":")
|
||||
.append(Process.myUid())
|
||||
.toString()
|
||||
)
|
||||
.buildUpon()
|
||||
.appendQueryParameter("v", 7.toString())
|
||||
.appendQueryParameter("cv", 9.toString())
|
||||
.build()
|
||||
), 0
|
||||
)
|
||||
return info != null && isSigned()
|
||||
}
|
||||
|
||||
open fun isSigned(): Boolean {
|
||||
if (BuildConfig.DEBUG)
|
||||
return true // Skip signature checks for dev builds
|
||||
if (Utilities.ATLEAST_P) {
|
||||
val info = context.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES)
|
||||
val signingInfo = info.signingInfo
|
||||
if (signingInfo.hasMultipleSigners()) return false
|
||||
return signingInfo.signingCertificateHistory.any { it.hashCode() == signatureHash }
|
||||
} else {
|
||||
val info = context.packageManager.getPackageInfo(packageName, PackageManager.GET_SIGNATURES)
|
||||
return if (info.signatures.any { it.hashCode() != signatureHash })
|
||||
false
|
||||
else
|
||||
info.signatures.isNotEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inner class CustomBridgeInfo(packageName: String) : BridgeInfo(packageName, 0) {
|
||||
override val signatureHash = whitelist[packageName]?.toInt() ?: -1
|
||||
private val disableWhitelist = prefs!!.getBoolean(LawnchairPreferences.IGNORE_FEED_WHITELIST, false)
|
||||
override fun isSigned(): Boolean {
|
||||
if (signatureHash == -1 && Utilities.ATLEAST_P) {
|
||||
val info = context.packageManager
|
||||
.getPackageInfo(packageName, PackageManager.GET_SIGNING_CERTIFICATES)
|
||||
val signingInfo = info.signingInfo
|
||||
if (signingInfo.hasMultipleSigners()) return false
|
||||
signingInfo.signingCertificateHistory.forEach {
|
||||
val hash = Integer.toHexString(it.hashCode())
|
||||
Log.d(TAG, "Feed provider $packageName(0x$hash) isn't whitelisted")
|
||||
}
|
||||
}
|
||||
return disableWhitelist || signatureHash != -1 && super.isSigned()
|
||||
}
|
||||
}
|
||||
|
||||
private inner class PixelBridgeInfo(packageName: String, signatureHashRes: Int) :
|
||||
BridgeInfo(packageName, signatureHashRes) {
|
||||
override val supportsSmartspace get() = isAvailable()
|
||||
}
|
||||
|
||||
companion object : SingletonHolder<FeedBridge, Context>(
|
||||
ensureOnMainThread(
|
||||
useApplicationContext(::FeedBridge)
|
||||
)
|
||||
) {
|
||||
private const val TAG = "FeedBridge"
|
||||
private const val overlayAction = "com.android.launcher3.WINDOW_OVERLAY"
|
||||
|
||||
private val whitelist = mapOf<String, Long>(
|
||||
"ua.itaysonlab.homefeeder" to 0x887456ed, // HomeFeeder, t.me/homefeeder
|
||||
"launcher.libre.dev" to 0x2e9dbab5 // Librechair, t.me/librechair
|
||||
)
|
||||
|
||||
fun getAvailableProviders(context: Context) = context.packageManager
|
||||
.queryIntentServices(
|
||||
Intent(overlayAction).setData(Uri.parse("app://${context.packageName}")),
|
||||
PackageManager.GET_META_DATA
|
||||
)
|
||||
.map { it.serviceInfo.applicationInfo }
|
||||
.distinct()
|
||||
.filter { getInstance(context).CustomBridgeInfo(it.packageName).isSigned() }
|
||||
|
||||
@JvmStatic
|
||||
fun useBridge(context: Context) = getInstance(context).let { it.shouldUseFeed || it.customBridgeAvailable() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ch.deletescape.lawnchair;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.systemui.plugins.shared.LauncherOverlayManager;
|
||||
|
||||
import ch.deletescape.nexuslauncher.OverlayCallbackImpl;
|
||||
|
||||
public class LawnchairLauncher extends Launcher {
|
||||
@Override
|
||||
protected LauncherOverlayManager getDefaultOverlay() {
|
||||
return new OverlayCallbackImpl(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package ch.deletescape.lawnchair;
|
||||
|
||||
import com.android.launcher3.uioverrides.QuickstepLauncher;
|
||||
import com.android.systemui.plugins.shared.LauncherOverlayManager;
|
||||
|
||||
import ch.deletescape.nexuslauncher.OverlayCallbackImpl;
|
||||
|
||||
public class LawnchairLauncherQuickstep extends QuickstepLauncher {
|
||||
@Override
|
||||
protected LauncherOverlayManager getDefaultOverlay() {
|
||||
return new OverlayCallbackImpl(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of Lawnchair Launcher.
|
||||
*
|
||||
* Lawnchair Launcher is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Lawnchair Launcher is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Lawnchair Launcher. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ch.deletescape.lawnchair
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Looper
|
||||
import com.android.launcher3.util.Executors.MAIN_EXECUTOR
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.ExecutionException
|
||||
|
||||
|
||||
fun <T, A>ensureOnMainThread(creator: (A) -> T): (A) -> T {
|
||||
return { it ->
|
||||
if (Looper.myLooper() == Looper.getMainLooper()) {
|
||||
creator(it)
|
||||
} else {
|
||||
try {
|
||||
MAIN_EXECUTOR.submit(Callable { creator(it) }).get()
|
||||
} catch (e: InterruptedException) {
|
||||
throw RuntimeException(e)
|
||||
} catch (e: ExecutionException) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun <T>useApplicationContext(creator: (Context) -> T): (Context) -> T {
|
||||
return { it -> creator(it.applicationContext) }
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of Lawnchair Launcher.
|
||||
*
|
||||
* Lawnchair Launcher is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Lawnchair Launcher is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Lawnchair Launcher. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package ch.deletescape.lawnchair.util
|
||||
|
||||
import android.content.Context
|
||||
import ch.deletescape.lawnchair.ensureOnMainThread
|
||||
import ch.deletescape.lawnchair.useApplicationContext
|
||||
|
||||
// Source: https://medium.com/@BladeCoder/kotlin-singletons-with-argument-194ef06edd9e
|
||||
open class SingletonHolder<out T, in A>(creator: (A) -> T) {
|
||||
private var creator: ((A) -> T)? = creator
|
||||
@Volatile
|
||||
private var instance: T? = null
|
||||
|
||||
open fun getInstance(arg: A): T {
|
||||
val i = instance
|
||||
if (i != null) {
|
||||
return i
|
||||
}
|
||||
|
||||
return synchronized(this) {
|
||||
val i2 = instance
|
||||
if (i2 != null) {
|
||||
i2
|
||||
} else {
|
||||
val created = creator!!(arg)
|
||||
instance = created
|
||||
creator = null
|
||||
created
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun dangerousGetInstance() = instance
|
||||
}
|
||||
|
||||
open class LawnchairSingletonHolder<out T>(creator: (Context) -> T)
|
||||
: SingletonHolder<T, Context>(ensureOnMainThread(useApplicationContext(creator)))
|
||||
@@ -74,6 +74,15 @@ class LawnchairPreferences(val context: Context) {
|
||||
@kotlin.jvm.JvmField
|
||||
var MAKE_COLORED_BACKGROUNDS: String = "pref_makeColoredBackgrounds"
|
||||
|
||||
@kotlin.jvm.JvmField
|
||||
var IGNORE_FEED_WHITELIST: String = "pref_ignoreFeedWhitelist"
|
||||
|
||||
@kotlin.jvm.JvmField
|
||||
var FEED_PROVIDER: String = "pref_feedProvider"
|
||||
|
||||
@kotlin.jvm.JvmField
|
||||
var ENABLE_MINUS_ONE: String = "pref_enableMinusOne"
|
||||
|
||||
fun getInstance(context: Context?): SharedPreferences? = when {
|
||||
context == null -> null
|
||||
INSTANCE == null -> Utilities.getPrefs(context)
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
package ch.deletescape.nexuslauncher;
|
||||
|
||||
import static ch.deletescape.lawnchair.util.preferences.LawnchairPreferences.ENABLE_MINUS_ONE;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.Utilities;
|
||||
import com.android.systemui.plugins.shared.LauncherOverlayManager;
|
||||
import com.android.systemui.plugins.shared.LauncherOverlayManager.LauncherOverlay;
|
||||
|
||||
import com.google.android.libraries.launcherclient.ISerializableScrollCallback;
|
||||
import com.google.android.libraries.launcherclient.LauncherClient;
|
||||
import com.google.android.libraries.launcherclient.LauncherClientCallbacks;
|
||||
import com.google.android.libraries.launcherclient.StaticInteger;
|
||||
|
||||
import ch.deletescape.lawnchair.FeedBridge;
|
||||
import ch.deletescape.lawnchair.util.preferences.LawnchairPreferences;
|
||||
|
||||
/**
|
||||
* Implements {@link LauncherOverlay} and passes all the corresponding events to {@link
|
||||
* LauncherClient}. {@see setClient}
|
||||
*
|
||||
* <p>Implements {@link LauncherClientCallbacks} and sends all the corresponding callbacks to {@link
|
||||
* Launcher}.
|
||||
*/
|
||||
public class OverlayCallbackImpl
|
||||
implements LauncherOverlay, LauncherClientCallbacks, LauncherOverlayManager,
|
||||
OnSharedPreferenceChangeListener, ISerializableScrollCallback {
|
||||
|
||||
final static String PREF_PERSIST_FLAGS = "pref_persistent_flags";
|
||||
|
||||
private final Launcher mLauncher;
|
||||
private final LauncherClient mClient;
|
||||
|
||||
private LauncherOverlayCallbacks mLauncherOverlayCallbacks;
|
||||
private boolean mWasOverlayAttached = false;
|
||||
boolean mFlagsChanged = false;
|
||||
private int mFlags;
|
||||
|
||||
public OverlayCallbackImpl(Launcher launcher) {
|
||||
SharedPreferences prefs = Utilities.getPrefs(launcher);
|
||||
|
||||
mLauncher = launcher;
|
||||
mClient = new LauncherClient(mLauncher, this, new StaticInteger(
|
||||
(prefs.getBoolean(LawnchairPreferences.ENABLE_MINUS_ONE,
|
||||
FeedBridge.useBridge(launcher)) ? 1 : 0) | 2 | 4 | 8));
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceProvideChanged() {
|
||||
mClient.redraw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
mClient.onAttachedToWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetachedFromWindow() {
|
||||
mClient.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openOverlay() {
|
||||
mClient.showOverlay(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideOverlay(boolean animate) {
|
||||
mClient.hideOverlay(animate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hideOverlay(int duration) {
|
||||
mClient.hideOverlay(duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startSearch(byte[] config, Bundle extras) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Activity activity, Bundle bundle) {
|
||||
// Not called
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStarted(Activity activity) {
|
||||
mClient.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResumed(Activity activity) {
|
||||
mClient.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityPaused(Activity activity) {
|
||||
mClient.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityStopped(Activity activity) {
|
||||
mClient.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) { }
|
||||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
mClient.mDestroyed = true;
|
||||
mLauncher.getSharedPrefs().unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
if (ENABLE_MINUS_ONE.equals(key)) {
|
||||
mClient.showOverlay(prefs.getBoolean(ENABLE_MINUS_ONE, FeedBridge.useBridge(mLauncher)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOverlayScrollChanged(float progress) {
|
||||
if (mLauncherOverlayCallbacks != null) {
|
||||
mLauncherOverlayCallbacks.onScrollChanged(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceStateChanged(boolean overlayAttached, boolean hotwordActive) {
|
||||
this.onServiceStateChanged(overlayAttached);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceStateChanged(boolean overlayAttached) {
|
||||
if (overlayAttached != mWasOverlayAttached) {
|
||||
mWasOverlayAttached = overlayAttached;
|
||||
mLauncher.setLauncherOverlay(overlayAttached ? this : null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollInteractionBegin() {
|
||||
mClient.startScroll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollInteractionEnd() {
|
||||
mClient.endScroll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScrollChange(float progress, boolean rtl) {
|
||||
mClient.setScroll(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOverlayCallbacks(LauncherOverlayCallbacks callbacks) {
|
||||
mLauncherOverlayCallbacks = callbacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPersistentFlags(int flags) {
|
||||
flags &= (8 | 16);
|
||||
if (flags != mFlags) {
|
||||
mFlagsChanged = true;
|
||||
mFlags = flags;
|
||||
Utilities.getDevicePrefs(mLauncher).edit().putInt(PREF_PERSIST_FLAGS, flags).apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import ch.deletescape.lawnchair.FeedBridge;
|
||||
|
||||
public class BaseClientService implements ServiceConnection {
|
||||
private boolean mConnected;
|
||||
private final Context mContext;
|
||||
private final int mFlags;
|
||||
private final ServiceConnection mBridge;
|
||||
|
||||
BaseClientService(Context context, int flags) {
|
||||
mContext = context;
|
||||
mFlags = flags;
|
||||
mBridge = FeedBridge.useBridge(context)
|
||||
? new LauncherClientBridge(this, flags)
|
||||
: this;
|
||||
}
|
||||
|
||||
public final boolean connect() {
|
||||
if (!mConnected) {
|
||||
try {
|
||||
mConnected = mContext.bindService(LauncherClient.getIntent(mContext,
|
||||
FeedBridge.useBridge(mContext)), mBridge, mFlags);
|
||||
} catch (Throwable e) {
|
||||
Log.e("LauncherClient", "Unable to connect to overlay service", e);
|
||||
}
|
||||
}
|
||||
return mConnected;
|
||||
}
|
||||
|
||||
public final void disconnect() {
|
||||
if (mConnected) {
|
||||
mContext.unbindService(mBridge);
|
||||
mConnected = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
public interface IScrollCallback {
|
||||
void onOverlayScrollChanged(float progress);
|
||||
|
||||
void onServiceStateChanged(boolean overlayAttached);
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
public interface ISerializableScrollCallback extends IScrollCallback {
|
||||
void setPersistentFlags(int flags);
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.Point;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Handler.Callback;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Log;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
import ch.deletescape.lawnchair.FeedBridge;
|
||||
import ch.deletescape.lawnchair.FeedBridge.BridgeInfo;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class LauncherClient {
|
||||
private static int apiVersion = -1;
|
||||
|
||||
private ILauncherOverlay mOverlay;
|
||||
public final IScrollCallback mScrollCallback;
|
||||
|
||||
public final BaseClientService mBaseService;
|
||||
public final LauncherClientService mLauncherService;
|
||||
|
||||
public final BroadcastReceiver googleInstallListener = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
mBaseService.disconnect();
|
||||
mLauncherService.disconnect();
|
||||
LauncherClient.loadApiVersion(context);
|
||||
if ((mActivityState & 2) != 0) {
|
||||
reconnect();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private int mActivityState = 0;
|
||||
private int mServiceState = 0;
|
||||
public int mFlags;
|
||||
|
||||
public LayoutParams mLayoutParams;
|
||||
public OverlayCallback mOverlayCallback;
|
||||
public final Activity mActivity;
|
||||
|
||||
public boolean mDestroyed = false;
|
||||
private Bundle mLayoutBundle;
|
||||
|
||||
public class OverlayCallback extends ILauncherOverlayCallback.Stub implements Callback {
|
||||
public LauncherClient mClient;
|
||||
private final Handler mUIHandler = new Handler(Looper.getMainLooper(), this);
|
||||
public Window mWindow;
|
||||
private boolean mWindowHidden = false;
|
||||
public WindowManager mWindowManager;
|
||||
int mWindowShift;
|
||||
|
||||
@Override
|
||||
public final void overlayScrollChanged(float f) {
|
||||
mUIHandler.removeMessages(2);
|
||||
Message.obtain(mUIHandler, 2, f).sendToTarget();
|
||||
if (f > 0f && mWindowHidden) {
|
||||
mWindowHidden = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void overlayStatusChanged(int i) {
|
||||
Message.obtain(mUIHandler, 4, i, 0).sendToTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleMessage(Message message) {
|
||||
if (mClient == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (message.what) {
|
||||
case 2:
|
||||
if ((mClient.mServiceState & 1) != 0) {
|
||||
float floatValue = (float) message.obj;
|
||||
mClient.mScrollCallback.onOverlayScrollChanged(floatValue);
|
||||
}
|
||||
return true;
|
||||
case 3:
|
||||
WindowManager.LayoutParams attributes = mWindow.getAttributes();
|
||||
if ((Boolean) message.obj) {
|
||||
attributes.x = mWindowShift;
|
||||
attributes.flags |= 512;
|
||||
} else {
|
||||
attributes.x = 0;
|
||||
attributes.flags &= -513;
|
||||
}
|
||||
mWindowManager.updateViewLayout(mWindow.getDecorView(), attributes);
|
||||
return true;
|
||||
case 4:
|
||||
mClient.setServiceState(message.arg1);
|
||||
if (mClient.mScrollCallback instanceof ISerializableScrollCallback) {
|
||||
((ISerializableScrollCallback) mClient.mScrollCallback).setPersistentFlags(message.arg1);
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LauncherClient(Activity activity, IScrollCallback scrollCallback, StaticInteger flags) {
|
||||
mActivity = activity;
|
||||
mScrollCallback = scrollCallback;
|
||||
mBaseService = new BaseClientService(activity, Context.BIND_AUTO_CREATE | Context.BIND_IMPORTANT);
|
||||
mFlags = flags.mData;
|
||||
|
||||
mLauncherService = LauncherClientService.getInstance(activity);
|
||||
mLauncherService.mClient = new WeakReference<>(this);
|
||||
mOverlay = mLauncherService.mOverlay;
|
||||
|
||||
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
|
||||
intentFilter.addDataScheme("package");
|
||||
intentFilter.addDataSchemeSpecificPart("com.google.android.googlequicksearchbox", 0);
|
||||
mActivity.registerReceiver(googleInstallListener, intentFilter);
|
||||
|
||||
if (apiVersion <= 0) {
|
||||
loadApiVersion(activity);
|
||||
}
|
||||
|
||||
reconnect();
|
||||
if (mActivity.getWindow() != null &&
|
||||
mActivity.getWindow().peekDecorView() != null &&
|
||||
mActivity.getWindow().peekDecorView().isAttachedToWindow()) {
|
||||
onAttachedToWindow();
|
||||
}
|
||||
}
|
||||
|
||||
public final void onAttachedToWindow() {
|
||||
if (!mDestroyed) {
|
||||
setLayoutParams(mActivity.getWindow().getAttributes());
|
||||
}
|
||||
}
|
||||
|
||||
public final void onDetachedFromWindow() {
|
||||
if (!mDestroyed) {
|
||||
setLayoutParams(null);
|
||||
}
|
||||
}
|
||||
|
||||
public final void onResume() {
|
||||
if (!mDestroyed) {
|
||||
mActivityState |= 2;
|
||||
if (mOverlay != null && mLayoutParams != null) {
|
||||
try {
|
||||
if (apiVersion < 4) {
|
||||
mOverlay.onResume();
|
||||
} else {
|
||||
mOverlay.setActivityState(mActivityState);
|
||||
}
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void onPause() {
|
||||
if (!mDestroyed) {
|
||||
mActivityState &= -3;
|
||||
if (mOverlay != null && mLayoutParams != null) {
|
||||
try {
|
||||
if (apiVersion < 4) {
|
||||
mOverlay.onPause();
|
||||
} else {
|
||||
mOverlay.setActivityState(mActivityState);
|
||||
}
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void onStart() {
|
||||
Log.i("FEED", "1");
|
||||
if (!mDestroyed) {
|
||||
Log.i("FEED", "2");
|
||||
mLauncherService.setStopped(false);
|
||||
reconnect();
|
||||
mActivityState |= 1;
|
||||
if (mOverlay != null && mLayoutParams != null) {
|
||||
try {
|
||||
mOverlay.setActivityState(mActivityState);
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void onStop() {
|
||||
if (!mDestroyed) {
|
||||
mLauncherService.setStopped(true);
|
||||
mBaseService.disconnect();
|
||||
mActivityState &= -2;
|
||||
if (!(mOverlay == null || mLayoutParams == null)) {
|
||||
try {
|
||||
mOverlay.setActivityState(mActivityState);
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void reconnect() {
|
||||
if (!mDestroyed && (!mLauncherService.connect() || !mBaseService.connect())) {
|
||||
mActivity.runOnUiThread(() -> setServiceState(0));
|
||||
}
|
||||
}
|
||||
|
||||
public final void setLayoutParams(LayoutParams layoutParams) {
|
||||
if (mLayoutParams != layoutParams) {
|
||||
mLayoutParams = layoutParams;
|
||||
if (mLayoutParams != null) {
|
||||
exchangeConfig();
|
||||
} else if (mOverlay != null) {
|
||||
try {
|
||||
mOverlay.windowDetached(mActivity.isChangingConfigurations());
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
mOverlay = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void exchangeConfig() {
|
||||
if (mOverlay != null) {
|
||||
try {
|
||||
if (mOverlayCallback == null) {
|
||||
mOverlayCallback = new OverlayCallback();
|
||||
}
|
||||
OverlayCallback overlayCallback = mOverlayCallback;
|
||||
overlayCallback.mClient = this;
|
||||
overlayCallback.mWindowManager = mActivity.getWindowManager();
|
||||
Point point = new Point();
|
||||
overlayCallback.mWindowManager.getDefaultDisplay().getRealSize(point);
|
||||
overlayCallback.mWindowShift = -Math.max(point.x, point.y);
|
||||
overlayCallback.mWindow = mActivity.getWindow();
|
||||
if (apiVersion < 3) {
|
||||
mOverlay.windowAttached(mLayoutParams, mOverlayCallback, mFlags);
|
||||
} else {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable("layout_params", mLayoutParams);
|
||||
bundle.putParcelable("configuration", mActivity.getResources().getConfiguration());
|
||||
bundle.putInt("client_options", mFlags);
|
||||
if (mLayoutBundle != null) {
|
||||
bundle.putAll(mLayoutBundle);
|
||||
}
|
||||
mOverlay.windowAttached2(bundle, mOverlayCallback);
|
||||
}
|
||||
if (apiVersion >= 4) {
|
||||
mOverlay.setActivityState(mActivityState);
|
||||
} else if ((mActivityState & 2) != 0) {
|
||||
mOverlay.onResume();
|
||||
} else {
|
||||
mOverlay.onPause();
|
||||
}
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isConnected() {
|
||||
return mOverlay != null;
|
||||
}
|
||||
|
||||
public final void startScroll() {
|
||||
if (isConnected()) {
|
||||
try {
|
||||
mOverlay.startScroll();
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void endScroll() {
|
||||
if (isConnected()) {
|
||||
try {
|
||||
mOverlay.endScroll();
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void setScroll(float f) {
|
||||
if (isConnected()) {
|
||||
try {
|
||||
mOverlay.onScroll(f);
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int verifyAndGetAnimationFlags(int duration) {
|
||||
if ((duration <= 0) || (duration > 2047)) {
|
||||
throw new IllegalArgumentException("Invalid duration");
|
||||
}
|
||||
return 0x1 | duration << 2;
|
||||
}
|
||||
|
||||
public final void hideOverlay(boolean feedRunning) {
|
||||
if (mOverlay != null) {
|
||||
try {
|
||||
mOverlay.closeOverlay(feedRunning ? 1 : 0);
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void hideOverlay(int duration) {
|
||||
if (mOverlay != null) {
|
||||
try {
|
||||
mOverlay.closeOverlay(verifyAndGetAnimationFlags(duration));
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only used for accessibility
|
||||
public final void showOverlay(boolean feedRunning) {
|
||||
if (mOverlay != null) {
|
||||
try {
|
||||
mOverlay.openOverlay(feedRunning ? 1 : 0);
|
||||
} catch (RemoteException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final boolean startSearch(byte[] bArr, Bundle bundle) {
|
||||
if (apiVersion >= 6 && mOverlay != null) {
|
||||
try {
|
||||
return mOverlay.startSearch(bArr, bundle);
|
||||
} catch (Throwable e) {
|
||||
Log.e("DrawerOverlayClient", "Error starting session for search", e);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public final void redraw(Bundle layoutBundle) {
|
||||
mLayoutBundle = layoutBundle;
|
||||
if (mLayoutParams != null && apiVersion >= 7) {
|
||||
exchangeConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public final void redraw() {
|
||||
if (mLayoutParams != null && apiVersion >= 7) {
|
||||
exchangeConfig();
|
||||
}
|
||||
}
|
||||
|
||||
final void setOverlay(ILauncherOverlay overlay) {
|
||||
mOverlay = overlay;
|
||||
if (mOverlay == null) {
|
||||
setServiceState(0);
|
||||
} else if (mLayoutParams != null) {
|
||||
exchangeConfig();
|
||||
}
|
||||
}
|
||||
|
||||
private void setServiceState(int serviceState) {
|
||||
if (mServiceState != serviceState) {
|
||||
mServiceState = serviceState;
|
||||
mScrollCallback.onServiceStateChanged((serviceState & 1) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
static Intent getIntent(Context context, boolean proxy) {
|
||||
BridgeInfo bridgeInfo = proxy ? FeedBridge.Companion.getInstance(context).resolveBridge() : null;
|
||||
String pkg = context.getPackageName();
|
||||
return new Intent("com.android.launcher3.WINDOW_OVERLAY")
|
||||
.setPackage(bridgeInfo != null ? bridgeInfo.getPackageName() : "com.google.android.googlequicksearchbox")
|
||||
.setData(Uri.parse(new StringBuilder(pkg.length() + 18)
|
||||
.append("app://")
|
||||
.append(pkg)
|
||||
.append(":")
|
||||
.append(Process.myUid())
|
||||
.toString())
|
||||
.buildUpon()
|
||||
.appendQueryParameter("v", Integer.toString(7))
|
||||
.appendQueryParameter("cv", Integer.toString(9))
|
||||
.build());
|
||||
}
|
||||
|
||||
private static void loadApiVersion(Context context) {
|
||||
ResolveInfo resolveService = context.getPackageManager().resolveService(getIntent(context, false), PackageManager.GET_META_DATA);
|
||||
apiVersion = resolveService == null || resolveService.serviceInfo.metaData == null ?
|
||||
1 :
|
||||
resolveService.serviceInfo.metaData.getInt("service.api.version", 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ServiceConnection;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
|
||||
import amirz.aidlbridge.IBridge;
|
||||
import amirz.aidlbridge.IBridgeCallback;
|
||||
|
||||
public class LauncherClientBridge extends IBridgeCallback.Stub implements ServiceConnection {
|
||||
private static final String INTERFACE_DESCRIPTOR = "amirz.aidlbridge.IBridge";
|
||||
|
||||
private final BaseClientService mClientService;
|
||||
private final int mFlags;
|
||||
private ComponentName mConnectionName;
|
||||
|
||||
public LauncherClientBridge(BaseClientService launcherClientService, int flags) {
|
||||
mClientService = launcherClientService;
|
||||
mFlags = flags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
try {
|
||||
if (INTERFACE_DESCRIPTOR.equals(service.getInterfaceDescriptor())) {
|
||||
IBridge bridge = IBridge.Stub.asInterface(service);
|
||||
try {
|
||||
bridge.bindService(this, mFlags);
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
mClientService.onServiceConnected(name, service);
|
||||
mConnectionName = name;
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
if (mConnectionName != null) {
|
||||
mClientService.onServiceDisconnected(mConnectionName);
|
||||
mConnectionName = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
public interface LauncherClientCallbacks {
|
||||
void onOverlayScrollChanged(float f);
|
||||
|
||||
void onServiceStateChanged(boolean z, boolean z2);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.os.IBinder;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class LauncherClientService extends BaseClientService {
|
||||
public static LauncherClientService sInstance;
|
||||
public ILauncherOverlay mOverlay;
|
||||
public WeakReference<LauncherClient> mClient;
|
||||
private boolean mStopped;
|
||||
|
||||
static LauncherClientService getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new LauncherClientService(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private LauncherClientService(Context context) {
|
||||
super(context, Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY);
|
||||
}
|
||||
|
||||
public final void setStopped(boolean stopped) {
|
||||
mStopped = stopped;
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
setClient(ILauncherOverlay.Stub.asInterface(service));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected(ComponentName name) {
|
||||
setClient(null);
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
private void cleanUp() {
|
||||
if (mStopped && mOverlay == null) {
|
||||
disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private void setClient(ILauncherOverlay overlay) {
|
||||
mOverlay = overlay;
|
||||
LauncherClient client = getClient();
|
||||
if (client != null) {
|
||||
client.setOverlay(mOverlay);
|
||||
}
|
||||
}
|
||||
|
||||
public final LauncherClient getClient() {
|
||||
return mClient != null ? mClient.get() : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.google.android.libraries.launcherclient;
|
||||
|
||||
public class StaticInteger {
|
||||
public final int mData;
|
||||
|
||||
public StaticInteger(int data) {
|
||||
mData = data;
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@
|
||||
attributes and intent filters the same
|
||||
-->
|
||||
<activity
|
||||
android:name="com.android.launcher3.uioverrides.QuickstepLauncher"
|
||||
android:name="ch.deletescape.lawnchair.LawnchairLauncherQuickstep"
|
||||
android:launchMode="singleTask"
|
||||
android:clearTaskOnLaunch="true"
|
||||
android:stateNotNeeded="true"
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<integer name="bridge_signature_hash">0xB662CC2F</integer>
|
||||
<string name="bridge_download_url" translatable="false">https://github.com/amirzaidi/AIDLBridge/releases/download</string>
|
||||
<string name="bridge_download_version" translatable="false">v1</string>
|
||||
<string name="bridge_download_file" translatable="false">pixelbridge.apk</string>
|
||||
</resources>
|
||||
Reference in new issue
Block a user