sdk: Remove "long-press back to kill app" feature
Change-Id: I3df4469beb53eeee070cdc486d02bb95001d7f53
This commit is contained in:
@@ -949,8 +949,10 @@ public final class LineageSettings {
|
||||
|
||||
/**
|
||||
* Whether to allow killing of the foreground app by long-pressing the Back button
|
||||
* @deprecated
|
||||
* @hide
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String KILL_APP_LONGPRESS_BACK = "kill_app_longpress_back";
|
||||
|
||||
/** Protected Components
|
||||
|
||||
@@ -2952,8 +2952,10 @@ public final class LineageSettings {
|
||||
|
||||
/**
|
||||
* Whether to allow killing of the foreground app by long-pressing the Back button
|
||||
* @deprecated
|
||||
* @hide
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String KILL_APP_LONGPRESS_BACK = "kill_app_longpress_back";
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018-2019 The LineageOS Project
|
||||
* Copyright (C) 2018-2020 The LineageOS Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.lineageos.internal.util;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.StackInfo;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.ActivityOptions;
|
||||
import android.app.IActivityManager;
|
||||
@@ -26,7 +25,6 @@ import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
@@ -36,37 +34,6 @@ public class ActionUtils {
|
||||
private static final String TAG = ActionUtils.class.getSimpleName();
|
||||
private static final String SYSTEMUI_PACKAGE = "com.android.systemui";
|
||||
|
||||
/**
|
||||
* Kills the top most / most recent user application, but leaves out the launcher.
|
||||
* This is function governed by {@link Settings.Secure.KILL_APP_LONGPRESS_BACK}.
|
||||
*
|
||||
* @param context the current context, used to retrieve the package manager.
|
||||
* @param userId the ID of the currently active user
|
||||
* @return {@code true} when a user application was found and closed.
|
||||
*/
|
||||
public static boolean killForegroundApp(Context context, int userId) {
|
||||
try {
|
||||
return killForegroundAppInternal(context, userId);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "Could not kill foreground app");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean killForegroundAppInternal(Context context, int userId)
|
||||
throws RemoteException {
|
||||
final String packageName = getForegroundTaskPackageName(context, userId);
|
||||
|
||||
if (packageName == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final IActivityManager am = ActivityManagerNative.getDefault();
|
||||
am.forceStopPackage(packageName, UserHandle.USER_CURRENT);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to bring up the last activity in the stack before the current active one.
|
||||
*
|
||||
@@ -125,25 +92,6 @@ public class ActionUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String getForegroundTaskPackageName(Context context, int userId)
|
||||
throws RemoteException {
|
||||
final String defaultHomePackage = resolveCurrentLauncherPackage(context, userId);
|
||||
final IActivityManager am = ActivityManager.getService();
|
||||
final StackInfo focusedStack = am.getFocusedStackInfo();
|
||||
|
||||
if (focusedStack == null || focusedStack.topActivity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String packageName = focusedStack.topActivity.getPackageName();
|
||||
if (!packageName.equals(defaultHomePackage)
|
||||
&& !packageName.equals(SYSTEMUI_PACKAGE)) {
|
||||
return packageName;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String resolveCurrentLauncherPackage(Context context, int userId) {
|
||||
final Intent launcherIntent = new Intent(Intent.ACTION_MAIN)
|
||||
.addCategory(Intent.CATEGORY_HOME);
|
||||
|
||||
Reference in New Issue
Block a user