mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-27 15:26:58 +00:00
Added AppLaunchEventsPlugin which relays app launch/dismiss events to
all connected plugins. Listener for this plugin is added in PredictionAppTracker which receives all app events. Change-Id: Iec53d20272f6a587f78e3d84666efa4f02cf6962
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -41,12 +41,19 @@ import androidx.annotation.WorkerThread;
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.appprediction.PredictionUiStateManager.Client;
|
||||
import com.android.launcher3.model.AppLaunchTracker;
|
||||
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
|
||||
import com.android.systemui.plugins.AppLaunchEventsPlugin;
|
||||
import com.android.systemui.plugins.PluginListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Subclass of app tracker which publishes the data to the prediction engine and gets back results.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.Q)
|
||||
public class PredictionAppTracker extends AppLaunchTracker {
|
||||
public class PredictionAppTracker extends AppLaunchTracker
|
||||
implements PluginListener<AppLaunchEventsPlugin> {
|
||||
|
||||
private static final String TAG = "PredictionAppTracker";
|
||||
private static final boolean DBG = false;
|
||||
@@ -58,6 +65,7 @@ public class PredictionAppTracker extends AppLaunchTracker {
|
||||
|
||||
protected final Context mContext;
|
||||
private final Handler mMessageHandler;
|
||||
private final List<AppLaunchEventsPlugin> mAppLaunchEventsPluginsList;
|
||||
|
||||
// Accessed only on worker thread
|
||||
private AppPredictor mHomeAppPredictor;
|
||||
@@ -69,6 +77,10 @@ public class PredictionAppTracker extends AppLaunchTracker {
|
||||
InvariantDeviceProfile.INSTANCE.get(mContext).addOnChangeListener(this::onIdpChanged);
|
||||
|
||||
mMessageHandler.sendEmptyMessage(MSG_INIT);
|
||||
|
||||
mAppLaunchEventsPluginsList = new ArrayList<>();
|
||||
PluginManagerWrapper.INSTANCE.get(context)
|
||||
.addPluginListener(this, AppLaunchEventsPlugin.class, true);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@@ -96,7 +108,7 @@ public class PredictionAppTracker extends AppLaunchTracker {
|
||||
AppPredictionManager apm = mContext.getSystemService(AppPredictionManager.class);
|
||||
|
||||
if (apm == null) {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
AppPredictor predictor = apm.createAppPredictionSession(
|
||||
@@ -116,7 +128,7 @@ public class PredictionAppTracker extends AppLaunchTracker {
|
||||
*/
|
||||
@WorkerThread
|
||||
@Nullable
|
||||
public Bundle getAppPredictionContextExtras(Client client){
|
||||
public Bundle getAppPredictionContextExtras(Client client) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -167,12 +179,15 @@ public class PredictionAppTracker extends AppLaunchTracker {
|
||||
if (DBG) {
|
||||
Log.d(TAG, String.format("Sent immediate message to update %s", client));
|
||||
}
|
||||
|
||||
// Relay onReturnedToHome to every plugin.
|
||||
mAppLaunchEventsPluginsList.forEach(AppLaunchEventsPlugin::onReturnedToHome);
|
||||
}
|
||||
|
||||
@Override
|
||||
@UiThread
|
||||
public void onStartShortcut(String packageName, String shortcutId, UserHandle user,
|
||||
String container) {
|
||||
String container) {
|
||||
// TODO: Use the full shortcut info
|
||||
AppTarget target = new AppTarget.Builder(
|
||||
new AppTargetId("shortcut:" + shortcutId), packageName, user)
|
||||
@@ -180,6 +195,16 @@ public class PredictionAppTracker extends AppLaunchTracker {
|
||||
.build();
|
||||
|
||||
sendLaunch(target, container);
|
||||
|
||||
// Relay onStartShortcut info to every connected plugin.
|
||||
mAppLaunchEventsPluginsList
|
||||
.forEach(plugin -> plugin.onStartShortcut(
|
||||
packageName,
|
||||
shortcutId,
|
||||
user,
|
||||
container != null ? container : CONTAINER_DEFAULT)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -191,6 +216,14 @@ public class PredictionAppTracker extends AppLaunchTracker {
|
||||
.setClassName(cn.getClassName())
|
||||
.build();
|
||||
sendLaunch(target, container);
|
||||
|
||||
// Relay onStartApp to every connected plugin.
|
||||
mAppLaunchEventsPluginsList
|
||||
.forEach(plugin -> plugin.onStartApp(
|
||||
cn,
|
||||
user,
|
||||
container != null ? container : CONTAINER_DEFAULT)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +236,14 @@ public class PredictionAppTracker extends AppLaunchTracker {
|
||||
.setClassName(cn.getClassName())
|
||||
.build();
|
||||
sendDismiss(target, container);
|
||||
|
||||
// Relay onDismissApp to every connected plugin.
|
||||
mAppLaunchEventsPluginsList
|
||||
.forEach(plugin -> plugin.onDismissApp(
|
||||
cn,
|
||||
user,
|
||||
container != null ? container : CONTAINER_DEFAULT)
|
||||
);
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@@ -222,4 +263,14 @@ public class PredictionAppTracker extends AppLaunchTracker {
|
||||
private void sendDismiss(AppTarget target, String container) {
|
||||
sendEvent(target, container, AppTargetEvent.ACTION_DISMISS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginConnected(AppLaunchEventsPlugin appLaunchEventsPlugin, Context context) {
|
||||
mAppLaunchEventsPluginsList.add(appLaunchEventsPlugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginDisconnected(AppLaunchEventsPlugin appLaunchEventsPlugin) {
|
||||
mAppLaunchEventsPluginsList.remove(appLaunchEventsPlugin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.systemui.plugins;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.os.UserHandle;
|
||||
|
||||
import com.android.systemui.plugins.annotations.ProvidesInterface;
|
||||
|
||||
/**
|
||||
* Plugin interface which sends app launch events.
|
||||
*/
|
||||
@ProvidesInterface(action = AppLaunchEventsPlugin.ACTION, version = AppLaunchEventsPlugin.VERSION)
|
||||
public interface AppLaunchEventsPlugin extends Plugin {
|
||||
String ACTION = "com.android.systemui.action.PLUGIN_APP_EVENTS";
|
||||
int VERSION = 1;
|
||||
|
||||
/**
|
||||
* Receives onStartShortcut event from
|
||||
* {@link com.android.launcher3.appprediction.PredictionAppTracker}.
|
||||
*/
|
||||
void onStartShortcut(String packageName, String shortcutId, UserHandle user, String container);
|
||||
|
||||
/**
|
||||
* Receives onStartApp event from
|
||||
* {@link com.android.launcher3.appprediction.PredictionAppTracker}.
|
||||
*/
|
||||
void onStartApp(ComponentName componentName, UserHandle user, String container);
|
||||
|
||||
/**
|
||||
* Receives onDismissApp event from
|
||||
* {@link com.android.launcher3.appprediction.PredictionAppTracker}.
|
||||
*/
|
||||
void onDismissApp(ComponentName componentName, UserHandle user, String container);
|
||||
|
||||
/**
|
||||
* Receives onReturnedToHome event from
|
||||
* {@link com.android.launcher3.appprediction.PredictionAppTracker}.
|
||||
*/
|
||||
void onReturnedToHome();
|
||||
}
|
||||
Reference in New Issue
Block a user