diff options
| -rw-r--r-- | core/java/com/android/internal/app/ResolverActivity.java | 52 | ||||
| -rw-r--r-- | core/res/res/values/strings.xml | 4 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 1 | 
3 files changed, 57 insertions, 0 deletions
diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index e215517929c2..f0e721587659 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -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; diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 139c07f917c1..11c41e3b0c9f 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -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> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 723da4cf0eae..c24778035e1a 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -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" />  |