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

Commit 9cbe6b2c authored by Sander Alewijnse's avatar Sander Alewijnse Committed by Android Git Automerger
Browse files

am bbafde69: Add warning in the disambig for specific launchers.

* commit 'bbafde691fb61a5fbcef0e53b92f9e6c341fcda1':
  Add warning in the disambig for specific launchers.
parents c7db5d0b 6c9eee87
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
@@ -34,17 +34,21 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.LabeledIntent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.PatternMatcher;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -55,6 +59,7 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.android.internal.widget.ResolverDrawerLayout;

import java.text.Collator;
@@ -87,6 +92,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
    private int mIconSize;
    private int mMaxColumns;
    private int mLastSelected = ListView.INVALID_POSITION;
    private boolean mResolvingHome = false;

    private UsageStatsManager mUsm;
    private UsageStats mStats;
@@ -162,6 +168,9 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
                && categories.size() == 1
                && categories.contains(Intent.CATEGORY_HOME)) {
            titleResource = com.android.internal.R.string.whichHomeApplication;

            // Note: this field is not set to true in the compatibility version.
            mResolvingHome = true;
        } else {
            titleResource = 0;
        }
@@ -397,6 +406,15 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ResolveInfo resolveInfo = mAdapter.resolveInfoForPosition(position, true);
        if (mResolvingHome && hasManagedProfile()
                && !supportsManagedProfiles(resolveInfo)) {
            Toast.makeText(this, String.format(getResources().getString(
                    com.android.internal.R.string.activity_resolver_work_profiles_support),
                    resolveInfo.activityInfo.loadLabel(getPackageManager()).toString()),
                    Toast.LENGTH_LONG).show();
            return;
        }
        final int checkedPos = mGridView.getCheckedItemPosition();
        final boolean hasValidSelection = checkedPos != ListView.INVALID_POSITION;
        if (mAlwaysUseOption && (!hasValidSelection || mLastSelected != checkedPos)) {
@@ -411,6 +429,40 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic
        }
    }

    private boolean hasManagedProfile() {
        UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
        if (userManager == null) {
            return false;
        }

        try {
            List<UserInfo> profiles = userManager.getProfiles(getUserId());
            for (UserInfo userInfo : profiles) {
                if (userInfo != null && userInfo.isManagedProfile()) {
                    return true;
                }
            }
        } catch (SecurityException e) {
            return false;
        }
        return false;
    }

    private boolean supportsManagedProfiles(ResolveInfo resolveInfo) {
        try {
            ApplicationInfo appInfo = getPackageManager().getApplicationInfo(
                    resolveInfo.activityInfo.packageName, 0 /* default flags */);
            return versionNumberAtLeastL(appInfo.targetSdkVersion);
        } catch (NameNotFoundException e) {
            return false;
        }
    }

    private boolean versionNumberAtLeastL(int versionNumber) {
        // TODO: remove "|| true" once the build code for L is fixed.
        return versionNumber >= Build.VERSION_CODES.L || true;
    }

    private void setAlwaysButtonEnabled(boolean hasValidSelection, int checkedPos,
            boolean filtered) {
        boolean enabled = false;
+4 −0
Original line number Diff line number Diff line
@@ -4299,6 +4299,10 @@
         from the activity resolver to use just this once. [CHAR LIMIT=25] -->
    <string name="activity_resolver_use_once">Just once</string>

    <!-- Text for the toast that is shown when the user clicks on a launcher that
         doesn't support the work profile. [CHAR LIMIT=100] -->
    <string name="activity_resolver_work_profiles_support">%1$s doesn\'t support work profile.</string>

    <!-- Name of the default audio route for tablets when nothing
         is connected to a headphone or other wired audio output jack. [CHAR LIMIT=50] -->
    <string name="default_audio_route_name" product="tablet">Tablet</string>
+1 −0
Original line number Diff line number Diff line
@@ -356,6 +356,7 @@
  <java-symbol type="string" name="addToDictionary" />
  <java-symbol type="string" name="action_bar_home_description" />
  <java-symbol type="string" name="action_bar_up_description" />
  <java-symbol type="string" name="activity_resolver_work_profiles_support" />
  <java-symbol type="string" name="app_running_notification_title" />
  <java-symbol type="string" name="app_running_notification_text" />
  <java-symbol type="string" name="delete" />