165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/* 265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project 365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License"); 565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License. 665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at 765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * http://www.apache.org/licenses/LICENSE-2.0 965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software 1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS, 1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and 1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License. 1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.system; 1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.R; 203150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilsonimport com.android.tv.settings.users.RestrictedProfileDialogFragment; 2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.util.SettingsHelper; 223150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilsonimport com.android.tv.settings.dialog.DialogFragment; 233150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilsonimport com.android.tv.settings.dialog.DialogFragment.Action; 2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 253150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilsonimport android.app.Activity; 2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Context; 2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Intent; 2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.pm.PackageManager; 2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.pm.ResolveInfo; 3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Bundle; 3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.UserManager; 3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.provider.Settings; 3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 343150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilsonimport java.util.ArrayList; 3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport java.util.List; 3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/** 383150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson * Manages app security preferences. TODO: get a better icon from UX TODO: implement Notification 393150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson * listener settings 4065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 413150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilsonpublic class SecurityActivity extends Activity implements Action.Listener { 4265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 433150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final int CHECK_SET_ID = 1; 4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String PACKAGE_MIME_TYPE = "application/vnd.android.package-archive"; 4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String ACTION_RESTRICTED_PROFILE = "action_restricted_profile"; 463150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final String ACTION_SECURITY_UNKNOWN_SOURCES = "action_security_unknown_sources"; 473150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final String ACTION_SECURITY_UNKNOWN_SOURCES_OFF = 483150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson "action_security_unknown_sources_off"; 493150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final String ACTION_SECURITY_VERIFY_APPS = "action_security_verify_apps"; 503150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final String ACTION_SECURITY_VERIFY_APPS_ON = "action_security_verify_apps_on"; 513150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final String ACTION_SECURITY_VERIFY_APPS_OFF = "action_security_verify_apps_off"; 523150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final String ACTION_SECURITY_UNKNOWN_SOURCES_CONFIRM = 533150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson "action_security_verify_apps_confirm"; 543150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final String ACTION_SECURITY_UNKNOWN_SOURCES_CONFIRM_OK = 553150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson "action_security_verify_apps_confirm_ok"; 563150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final String ACTION_SECURITY_UNKNOWN_SOURCES_CONFIRM_CANCEL = 573150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson "action_security_verify_apps_confirm_cancel"; 583150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson 593150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private static final String TAG_RESTRICTED_PROFILE_SIDECAR_FRAGMENT = 603150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson "restricted_profile_sidecar"; 6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private SettingsHelper mHelper; 6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mVerifierInstalled; 643150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private DialogFragment mMainMenuDialogFragment; 6565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane protected void onCreate(Bundle savedInstanceState) { 6865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mHelper = new SettingsHelper(getApplicationContext()); 6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mVerifierInstalled = isVerifierInstalled(); 7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // Do this after setting up what's needed. 7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.onCreate(savedInstanceState); 723150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson mMainMenuDialogFragment = new DialogFragment.Builder() 733150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .breadcrumb(getString(R.string.header_category_personal)) 743150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.system_security)) 753150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .iconResourceId(R.drawable.ic_settings_security) 763150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .iconBackgroundColor(getResources().getColor(R.color.icon_background)) 773150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .actions(getMainMenuActions()).build(); 783150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson DialogFragment.add(getFragmentManager(), mMainMenuDialogFragment); 7965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 8065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 8165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 8265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onActionClicked(Action action) { 8365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (ACTION_RESTRICTED_PROFILE.equals(action.getKey())) { 843150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson getFragmentManager().beginTransaction().add(new RestrictedProfileDialogFragment(), 853150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson TAG_RESTRICTED_PROFILE_SIDECAR_FRAGMENT).commit(); 863150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } else if (ACTION_SECURITY_UNKNOWN_SOURCES.equals(action.getKey())) { 873150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson boolean isNonMarketAppsAllowed = isNonMarketAppsAllowed(); 883150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson ArrayList<Action> actions = new ArrayList<>(); 893150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson // Note we only use the check set id if the "on" is checked so if "off" is selected 903150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson // there is an animation of the check for "off". We don't want the same behavior for 913150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson // "on" because it has to go through a confirmation sub-dialog. 923150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson actions.add(new Action.Builder() 933150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .key(ACTION_SECURITY_UNKNOWN_SOURCES_CONFIRM) 943150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.settings_on)) 953150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .checked(isNonMarketAppsAllowed) 963150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .checkSetId(isNonMarketAppsAllowed ? CHECK_SET_ID : 0) 973150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build()); 983150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson actions.add(new Action.Builder() 993150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .key(ACTION_SECURITY_UNKNOWN_SOURCES_OFF) 1003150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.settings_off)) 1013150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .checked(!isNonMarketAppsAllowed) 1023150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .checkSetId(CHECK_SET_ID) 1033150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build()); 1043150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson 1053150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson DialogFragment dialogFragment = new DialogFragment.Builder() 1063150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .breadcrumb(getString(R.string.system_security)) 1073150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.security_unknown_sources_title)) 1083150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .description(getString(R.string.security_unknown_sources_desc)) 1093150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .actions(actions) 1103150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build(); 1113150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson DialogFragment.add(getFragmentManager(), dialogFragment); 1123150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } else if (ACTION_SECURITY_UNKNOWN_SOURCES_OFF.equals(action.getKey())) { 1133150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson setNonMarketAppsAllowed(false); 1143150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson mMainMenuDialogFragment.setActions(getMainMenuActions()); 1153150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson getFragmentManager().popBackStack(); 1163150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } else if (ACTION_SECURITY_UNKNOWN_SOURCES_CONFIRM.equals(action.getKey())) { 1173150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson // No point in issuing the confirmation sub-dialog if we're already "on". 1183150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson if (isNonMarketAppsAllowed()) { 1193150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson getFragmentManager().popBackStack(); 1203150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } else { 1213150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson ArrayList<Action> actions = new ArrayList<>(); 1223150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson actions.add(new Action.Builder() 1233150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .key(ACTION_SECURITY_UNKNOWN_SOURCES_CONFIRM_OK) 1243150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.settings_ok)) 1253150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build()); 1263150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson actions.add(new Action.Builder() 1273150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .key(ACTION_SECURITY_UNKNOWN_SOURCES_CONFIRM_CANCEL) 1283150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.settings_cancel)) 1293150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build()); 1303150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson 1313150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson DialogFragment dialogFragment = new DialogFragment.Builder() 1323150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .breadcrumb(getString(R.string.system_security)) 1333150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.security_unknown_sources_title)) 1343150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .description(getString(R.string.security_unknown_sources_confirm_desc)) 1353150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .actions(actions) 1363150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build(); 1373150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson DialogFragment.add(getFragmentManager(), dialogFragment); 1383150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } 1393150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } else if (ACTION_SECURITY_UNKNOWN_SOURCES_CONFIRM_OK.equals(action.getKey())) { 1403150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson setNonMarketAppsAllowed(true); 1413150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson mMainMenuDialogFragment.setActions(getMainMenuActions()); 1423150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson getFragmentManager().popBackStack(); 1433150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson getFragmentManager().popBackStack(); 1443150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } else if (ACTION_SECURITY_UNKNOWN_SOURCES_CONFIRM_CANCEL.equals(action.getKey())) { 1453150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson getFragmentManager().popBackStack(); 1463150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson getFragmentManager().popBackStack(); 1473150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } else if (ACTION_SECURITY_VERIFY_APPS.equals(action.getKey())) { 1483150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson boolean isVerifyAppsEnabled = mVerifierInstalled && isVerifyAppsEnabled(); 1493150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson 1503150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson ArrayList<Action> actions = new ArrayList<>(); 1513150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson actions.add(new Action.Builder() 1523150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .key(ACTION_SECURITY_VERIFY_APPS_ON) 1533150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.settings_on)) 1543150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .checked(isVerifyAppsEnabled) 1553150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .checkSetId(CHECK_SET_ID) 1563150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build()); 1573150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson actions.add(new Action.Builder() 1583150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .key(ACTION_SECURITY_VERIFY_APPS_OFF) 1593150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.settings_off)) 1603150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .checked(!isVerifyAppsEnabled) 1613150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .checkSetId(CHECK_SET_ID) 1623150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build()); 1633150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson 1643150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson DialogFragment dialogFragment = new DialogFragment.Builder() 1653150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .breadcrumb(getString(R.string.system_security)) 1663150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.security_verify_apps_title)) 1673150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .description(getString(R.string.security_verify_apps_desc)) 1683150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .actions(actions) 1693150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build(); 1703150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson DialogFragment.add(getFragmentManager(), dialogFragment); 1713150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } else if (ACTION_SECURITY_VERIFY_APPS_ON.equals(action.getKey())) { 1723150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson setVerifyAppsEnabled(true); 1733150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson mMainMenuDialogFragment.setActions(getMainMenuActions()); 1743150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson getFragmentManager().popBackStack(); 1753150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson } else if (ACTION_SECURITY_VERIFY_APPS_OFF.equals(action.getKey())) { 1763150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson setVerifyAppsEnabled(false); 1773150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson mMainMenuDialogFragment.setActions(getMainMenuActions()); 1783150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson getFragmentManager().popBackStack(); 17965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 18065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 18165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1823150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson private ArrayList<Action> getMainMenuActions() { 1833150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson boolean isNonMarketAppsAllowed = isNonMarketAppsAllowed(); 1843150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson ArrayList<Action> actions = new ArrayList<>(); 1853150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson actions.add(new Action.Builder() 1863150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .key(ACTION_SECURITY_UNKNOWN_SOURCES) 1873150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.security_unknown_sources_title)) 1883150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .description(mHelper.getStatusStringFromBoolean(isNonMarketAppsAllowed())) 1893150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build()); 1903150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson if (showVerifierSetting()) { 1913150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson actions.add(new Action.Builder() 1923150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .key(ACTION_SECURITY_VERIFY_APPS) 1933150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.security_verify_apps_title)) 1943150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .description(mHelper.getStatusStringFromBoolean(isVerifyAppsEnabled() 1953150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson && mVerifierInstalled)) 1963150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .enabled(mVerifierInstalled) 1973150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build()); 19865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 1993150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson actions.add(new Action.Builder().key(ACTION_RESTRICTED_PROFILE) 2003150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .title(getString(R.string.launcher_restricted_profile_app_name)) 2013150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .description(RestrictedProfileDialogFragment.getActionDescription(this)) 2023150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson .build()); 2033150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson return actions; 20465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 20565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 20665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean isNonMarketAppsAllowed() { 20765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return Settings.Global.getInt(getContentResolver(), 2083150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson Settings.Global.INSTALL_NON_MARKET_APPS, 0) > 0; 20965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 21065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 21165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private void setNonMarketAppsAllowed(boolean enabled) { 21265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final UserManager um = (UserManager) getSystemService(Context.USER_SERVICE); 21365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (um.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES)) { 21465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return; 21565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 21665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane // Change the system setting 21765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Settings.Global.putInt(getContentResolver(), Settings.Global.INSTALL_NON_MARKET_APPS, 2183150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson enabled ? 1 : 0); 21965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 22165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean isVerifyAppsEnabled() { 22265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return Settings.Global.getInt(getContentResolver(), 2233150b12e5df05eec2c3ebb85360661f1d034c188Andrew Wilson Settings.Global.PACKAGE_VERIFIER_ENABLE, 1) > 0; 22465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 22665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private void setVerifyAppsEnabled(boolean enable) { 22765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Settings.Global.putInt(getContentResolver(), Settings.Global.PACKAGE_VERIFIER_ENABLE, 22865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane enable ? 1 : 0); 22965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 23065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 23165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean isVerifierInstalled() { 23265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final PackageManager pm = getPackageManager(); 23365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final Intent verification = new Intent(Intent.ACTION_PACKAGE_NEEDS_VERIFICATION); 23465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane verification.setType(PACKAGE_MIME_TYPE); 23565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane verification.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); 23665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(verification, 0); 23765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return (receivers.size() > 0) ? true : false; 23865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 23965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 24065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean showVerifierSetting() { 24165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return Settings.Global.getInt(getContentResolver(), 24265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE, 1) > 0; 24365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 24565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane} 246