Adding Manage External Sources Settings

Added a settings fragment to manage external sources. It lists all
applications that have either requested REQUEST_INSTALL_PACKAGES or have
their app op changed from default.

Test: Will include in follow-up CL. Tracked in b/33792674

Bug: 31002700
Change-Id: Ibd2a1922be214b62aec4eefa45f7b9691256b205
This commit is contained in:
Suprabh Shukla
2016-12-16 14:44:05 -08:00
parent 27cb8b4a65
commit 57d92315a4
8 changed files with 345 additions and 0 deletions

View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import android.app.AlertDialog;
import android.app.AppOpsManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceChangeListener;
import com.android.settings.R;
import com.android.settings.applications.AppStateInstallAppsBridge.InstallAppsState;
public class ExternalSourcesDetails extends AppInfoWithHeader
implements OnPreferenceChangeListener {
private static final String KEY_EXTERNAL_SOURCES_SETTINGS_SWITCH =
"external_sources_settings_switch";
private static final String KEY_EXTERNAL_SOURCES_SETTINGS_DESC =
"external_sources_settings_description";
private AppStateInstallAppsBridge mAppBridge;
private AppOpsManager mAppOpsManager;
private SwitchPreference mSwitchPref;
private Preference mExternalSourcesSettingsDesc;
private InstallAppsState mInstallAppsState;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Context context = getActivity();
mAppBridge = new AppStateInstallAppsBridge(context, mState, null);
mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
addPreferencesFromResource(R.xml.external_sources_details);
mSwitchPref = (SwitchPreference) findPreference(KEY_EXTERNAL_SOURCES_SETTINGS_SWITCH);
mExternalSourcesSettingsDesc = findPreference(KEY_EXTERNAL_SOURCES_SETTINGS_DESC);
getPreferenceScreen().setTitle(R.string.install_other_apps);
mSwitchPref.setTitle(R.string.external_source_switch_title);
mExternalSourcesSettingsDesc.setSummary(R.string.install_all_warning);
mSwitchPref.setOnPreferenceChangeListener(this);
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean checked = (Boolean) newValue;
if (preference == mSwitchPref) {
if (mInstallAppsState != null && checked != mInstallAppsState.canInstallApps()) {
setCanInstallApps(checked);
refreshUi();
}
return true;
}
return false;
}
private void setCanInstallApps(boolean newState) {
mAppOpsManager.setMode(AppOpsManager.OP_REQUEST_INSTALL_PACKAGES,
mPackageInfo.applicationInfo.uid, mPackageName,
newState ? AppOpsManager.MODE_ALLOWED : AppOpsManager.MODE_ERRORED);
}
@Override
protected boolean refreshUi() {
mInstallAppsState = mAppBridge.createInstallAppsStateFor(mPackageName,
mPackageInfo.applicationInfo.uid);
final boolean canWrite = mInstallAppsState.canInstallApps();
mSwitchPref.setChecked(canWrite);
return true;
}
@Override
protected AlertDialog createDialog(int id, int errorCode) {
return null;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.MANAGE_EXTERNAL_SOURCES;
}
}