Adding "Delete all App Clones" option on Cloned Apps page.

This option is seen by clicking the '3-dot' menu on Settings->Cloned Apps page and requires:
1. Flag 'remove_all_cloned_apps' to be turned on.
2. Cloned UserId to be present in system.

Test: Manually setting the flag, creating clones.
Change-Id: I83ff40923f7932ed6b23cb831bdcd2cb9252d295
This commit is contained in:
Himanshu Gupta
2022-11-29 10:31:14 +00:00
parent 366649ed1c
commit 1648d68d49
4 changed files with 42 additions and 0 deletions

View File

@@ -56,4 +56,8 @@
android:id="@+id/reset_app_preferences" android:id="@+id/reset_app_preferences"
android:title="@string/reset_app_preferences" android:title="@string/reset_app_preferences"
android:showAsAction="never" /> android:showAsAction="never" />
<item
android:id="@+id/delete_all_app_clones"
android:title="@string/delete_all_app_clones"
android:showAsAction="never" />
</menu> </menu>

View File

@@ -6581,6 +6581,10 @@
<!-- Description for introduction of the cloned apps page [CHAR LIMIT=NONE]--> <!-- Description for introduction of the cloned apps page [CHAR LIMIT=NONE]-->
<string name="desc_cloned_apps_intro_text">Create a second instance of an app so that you can use two accounts at the same time.</string> <string name="desc_cloned_apps_intro_text">Create a second instance of an app so that you can use two accounts at the same time.</string>
<string name="cloned_apps_summary"><xliff:g id="cloned_apps_count">%1$s</xliff:g> cloned, <xliff:g id="allowed_apps_count">%2$d</xliff:g> available to clone</string> <string name="cloned_apps_summary"><xliff:g id="cloned_apps_count">%1$s</xliff:g> cloned, <xliff:g id="allowed_apps_count">%2$d</xliff:g> available to clone</string>
<!-- Description for cloned apps removal title [CHAR LIMIT=40]-->
<string name="delete_all_app_clones">Delete all App clones</string>
<!-- Description for cloned apps removal failure title [CHAR LIMIT=40]-->
<string name="delete_all_app_clones_failure">Delete all App clones failed</string>
<!-- Summary text when an app is being cloned [CHAR LIMIT=40] --> <!-- Summary text when an app is being cloned [CHAR LIMIT=40] -->
<string name="cloned_app_creation_summary">Creating&#8230;</string> <string name="cloned_app_creation_summary">Creating&#8230;</string>
<!-- Summary text after an app is cloned [CHAR LIMIT=40] --> <!-- Summary text after an app is cloned [CHAR LIMIT=40] -->

View File

@@ -169,6 +169,13 @@ public final class Utils extends com.android.settingslib.Utils {
*/ */
public static final String PROPERTY_CLONED_APPS_ENABLED = "cloned_apps_enabled"; public static final String PROPERTY_CLONED_APPS_ENABLED = "cloned_apps_enabled";
/**
* Whether or not Delete All App Clones sub-menu is available in the Cloned Apps page.
* Default is false.
*/
public static final String PROPERTY_DELETE_ALL_APP_CLONES_ENABLED =
"delete_all_app_clones_enabled";
/** /**
* Finds a matching activity for a preference's intent. If a matching * Finds a matching activity for a preference's intent. If a matching
* activity is not found, it will remove the preference. * activity is not found, it will remove the preference.

View File

@@ -21,6 +21,7 @@ import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_SETTINGS_PAGE_SCROLL; import static com.android.internal.jank.InteractionJankMonitor.CUJ_SETTINGS_PAGE_SCROLL;
import static com.android.settings.ChangeIds.CHANGE_RESTRICT_SAW_INTENT; import static com.android.settings.ChangeIds.CHANGE_RESTRICT_SAW_INTENT;
import static com.android.settings.Utils.PROPERTY_DELETE_ALL_APP_CLONES_ENABLED;
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_ALL; import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_ALL;
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_BATTERY_OPTIMIZED; import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_BATTERY_OPTIMIZED;
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_BATTERY_RESTRICTED; import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_BATTERY_RESTRICTED;
@@ -53,11 +54,13 @@ import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.IBinder; import android.os.IBinder;
import android.os.IUserManager;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.preference.PreferenceFrameLayout; import android.preference.PreferenceFrameLayout;
import android.provider.DeviceConfig;
import android.provider.Settings; import android.provider.Settings;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.ArraySet; import android.util.ArraySet;
@@ -76,6 +79,7 @@ import android.widget.Filter;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.SearchView; import android.widget.SearchView;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@@ -831,6 +835,11 @@ public class ManageApplications extends InstrumentedFragment
if (searchItem != null) { if (searchItem != null) {
searchItem.setVisible(false); searchItem.setVisible(false);
} }
mOptionsMenu.findItem(R.id.delete_all_app_clones)
.setVisible(mListType == LIST_TYPE_CLONED_APPS && DeviceConfig.getBoolean(
DeviceConfig.NAMESPACE_APP_CLONING, PROPERTY_DELETE_ALL_APP_CLONES_ENABLED,
false) && Utils.getCloneUserId(getContext()) != -1);
} }
@Override @Override
@@ -871,6 +880,24 @@ public class ManageApplications extends InstrumentedFragment
startActivityForResult(intent, ADVANCED_SETTINGS); startActivityForResult(intent, ADVANCED_SETTINGS);
} }
return true; return true;
} else if (i == R.id.delete_all_app_clones) {
int clonedUserId = Utils.getCloneUserId(getContext());
if (clonedUserId == -1) {
// No Apps Cloned Till now. Do Nothing.
return false;
}
IUserManager um = IUserManager.Stub.asInterface(
ServiceManager.getService(Context.USER_SERVICE));
try {
// Warning: This removes all the data, media & images present in cloned user.
um.removeUser(clonedUserId);
mApplications.rebuild();
} catch (RemoteException e) {
Log.e(TAG, "Failed to remove cloned apps", e);
Toast.makeText(getContext(),
getContext().getString(R.string.delete_all_app_clones_failure),
Toast.LENGTH_LONG).show();
}
} else {// Handle the home button } else {// Handle the home button
return false; return false;
} }