Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1648d68d authored by Himanshu Gupta's avatar Himanshu Gupta
Browse files

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
parent 366649ed
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -56,4 +56,8 @@
        android:id="@+id/reset_app_preferences"
        android:title="@string/reset_app_preferences"
        android:showAsAction="never" />
    <item
        android:id="@+id/delete_all_app_clones"
        android:title="@string/delete_all_app_clones"
        android:showAsAction="never" />
</menu>
+4 −0
Original line number Diff line number Diff line
@@ -6581,6 +6581,10 @@
    <!-- 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="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] -->
    <string name="cloned_app_creation_summary">Creating&#8230;</string>
    <!-- Summary text after an app is cloned [CHAR LIMIT=40] -->
+7 −0
Original line number Diff line number Diff line
@@ -169,6 +169,13 @@ public final class Utils extends com.android.settingslib.Utils {
     */
    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
     * activity is not found, it will remove the preference.
+27 −0
Original line number Diff line number Diff line
@@ -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.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_BATTERY_OPTIMIZED;
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.Environment;
import android.os.IBinder;
import android.os.IUserManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.PreferenceFrameLayout;
import android.provider.DeviceConfig;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.ArraySet;
@@ -76,6 +79,7 @@ import android.widget.Filter;
import android.widget.FrameLayout;
import android.widget.SearchView;
import android.widget.Spinner;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -831,6 +835,11 @@ public class ManageApplications extends InstrumentedFragment
        if (searchItem != null) {
            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
@@ -871,6 +880,24 @@ public class ManageApplications extends InstrumentedFragment
                startActivityForResult(intent, ADVANCED_SETTINGS);
            }
            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
            return false;
        }