Move ManageApplications to sub package and remove dead code

Bug: 64804294
Test: rerun test
Change-Id: I23cbd8da9b65f52470030ba3b9b676ece2bada11
This commit is contained in:
Fan Zhang
2017-10-11 16:44:41 -07:00
parent 350ccf53f2
commit a8cac7a409
35 changed files with 122 additions and 325 deletions

View File

@@ -0,0 +1,80 @@
/*
* Copyright (C) 2015 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.manageapplications;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.android.settings.R;
import com.android.settingslib.applications.ApplicationsState;
// View Holder used when displaying views
public class AppViewHolder {
public ApplicationsState.AppEntry entry;
public View rootView;
public TextView appName;
public ImageView appIcon;
public TextView summary;
public TextView disabled;
static public AppViewHolder createOrRecycle(LayoutInflater inflater, View convertView) {
if (convertView == null) {
convertView = inflater.inflate(R.layout.preference_app, null);
inflater.inflate(R.layout.widget_text_views,
(ViewGroup) convertView.findViewById(android.R.id.widget_frame));
// Creates a ViewHolder and store references to the two children views
// we want to bind data to.
AppViewHolder holder = new AppViewHolder();
holder.rootView = convertView;
holder.appName = (TextView) convertView.findViewById(android.R.id.title);
holder.appIcon = (ImageView) convertView.findViewById(android.R.id.icon);
holder.summary = (TextView) convertView.findViewById(R.id.widget_text1);
holder.disabled = (TextView) convertView.findViewById(R.id.widget_text2);
convertView.setTag(holder);
return holder;
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
return (AppViewHolder)convertView.getTag();
}
}
void updateSizeText(CharSequence invalidSizeStr, int whichSize) {
if (ManageApplications.DEBUG) Log.i(ManageApplications.TAG, "updateSizeText of "
+ entry.label + " " + entry + ": " + entry.sizeStr);
if (entry.sizeStr != null) {
switch (whichSize) {
case ManageApplications.SIZE_INTERNAL:
summary.setText(entry.internalSizeStr);
break;
case ManageApplications.SIZE_EXTERNAL:
summary.setText(entry.externalSizeStr);
break;
default:
summary.setText(entry.sizeStr);
break;
}
} else if (entry.size == ApplicationsState.SIZE_INVALID) {
summary.setText(invalidSizeStr);
}
}
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2015 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.manageapplications;
import android.app.Fragment;
/**
* FileViewHolderController handles adapting the AppViewHolder to work as a general purpose
* storage categorization preference in the ManageApplications view.
*/
public interface FileViewHolderController {
/**
* Begins a synchronous query for statistics for the files.
*/
void queryStats();
/**
* Returns if the preference should be shown.
*/
boolean shouldShow();
/**
* Initializes the view within an AppViewHolder.
* @param holder The holder to use to initialize.
*/
void setupView(AppViewHolder holder);
/**
* Handles the behavior when the view is clicked.
* @param fragment Fragment where the click originated.
*/
void onClick(Fragment fragment);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,92 @@
/*
* Copyright (C) 2016 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.manageapplications;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.InsetDrawable;
import android.os.UserHandle;
import android.provider.DocumentsContract;
import android.support.annotation.WorkerThread;
import android.text.format.Formatter;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.applications.StorageStatsSource;
import java.io.IOException;
/**
* MusicViewHolderController controls an Audio/Music file view in the ManageApplications view.
*/
public class MusicViewHolderController implements FileViewHolderController {
private static final String TAG = "MusicViewHolderCtrl";
private static final String AUTHORITY_MEDIA = "com.android.providers.media.documents";
private static final int INSET_SIZE = 24; // dp
private Context mContext;
private StorageStatsSource mSource;
private String mVolumeUuid;
private long mMusicSize;
private UserHandle mUser;
public MusicViewHolderController(
Context context, StorageStatsSource source, String volumeUuid, UserHandle user) {
mContext = context;
mSource = source;
mVolumeUuid = volumeUuid;
mUser = user;
}
@Override
@WorkerThread
public void queryStats() {
try {
mMusicSize = mSource.getExternalStorageStats(mVolumeUuid, mUser).audioBytes;
} catch (IOException e) {
mMusicSize = 0;
Log.w(TAG, e);
}
}
@Override
public boolean shouldShow() {
return true;
}
@Override
public void setupView(AppViewHolder holder) {
holder.appIcon.setImageDrawable(
new InsetDrawable(mContext.getDrawable(R.drawable.ic_headset_24dp), INSET_SIZE));
holder.appName.setText(mContext.getText(R.string.audio_files_title));
holder.summary.setText(Formatter.formatFileSize(mContext, mMusicSize));
}
@Override
public void onClick(Fragment fragment) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
DocumentsContract.buildRootUri(AUTHORITY_MEDIA, "audio_root"),
DocumentsContract.Root.MIME_TYPE_ITEM);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(Intent.EXTRA_USER_ID, mUser);
Utils.launchIntent(fragment, intent);
}
}

View File

@@ -0,0 +1,90 @@
/*
* Copyright (C) 2016 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.manageapplications;
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.InsetDrawable;
import android.os.UserHandle;
import android.support.annotation.WorkerThread;
import android.text.format.Formatter;
import android.util.Log;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settingslib.applications.StorageStatsSource;
import java.io.IOException;
/** PhotosViewHolderController controls an Audio/Music file view in the ManageApplications view. */
public class PhotosViewHolderController implements FileViewHolderController {
private static final String TAG = "PhotosViewHolderCtrl";
private static final String IMAGE_MIME_TYPE = "image/*";
private static final int INSET_SIZE = 24; // dp
private Context mContext;
private StorageStatsSource mSource;
private String mVolumeUuid;
private long mFilesSize;
private UserHandle mUser;
public PhotosViewHolderController(
Context context, StorageStatsSource source, String volumeUuid, UserHandle user) {
mContext = context;
mSource = source;
mVolumeUuid = volumeUuid;
mUser = user;
}
@Override
@WorkerThread
public void queryStats() {
try {
StorageStatsSource.ExternalStorageStats stats =
mSource.getExternalStorageStats(mVolumeUuid, mUser);
mFilesSize = stats.imageBytes + stats.videoBytes;
} catch (IOException e) {
mFilesSize = 0;
Log.w(TAG, e);
}
}
@Override
public boolean shouldShow() {
return true;
}
@Override
public void setupView(AppViewHolder holder) {
holder.appIcon.setImageDrawable(
new InsetDrawable(mContext.getDrawable(R.drawable.ic_photo_library), INSET_SIZE));
holder.appName.setText(mContext.getText(R.string.storage_detail_images));
holder.summary.setText(Formatter.formatFileSize(mContext, mFilesSize));
}
@Override
public void onClick(Fragment fragment) {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT);
intent.setType(IMAGE_MIME_TYPE);
intent.putExtra(Intent.EXTRA_FROM_STORAGE, true);
Utils.launchIntent(fragment, intent);
}
}

View File

@@ -0,0 +1,72 @@
/*
* 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.manageapplications;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.text.TextUtils;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnCreate;
import com.android.settingslib.core.lifecycle.events.OnSaveInstanceState;
public class ResetAppPrefPreferenceController extends AbstractPreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnCreate, OnSaveInstanceState {
private ResetAppsHelper mResetAppsHelper;
public ResetAppPrefPreferenceController(Context context, Lifecycle lifecycle) {
super(context);
mResetAppsHelper = new ResetAppsHelper(context);
if (lifecycle != null) {
lifecycle.addObserver(this);
}
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
return false;
}
mResetAppsHelper.buildResetDialog();
return true;
}
@Override
public boolean isAvailable() {
return true;
}
@Override
public String getPreferenceKey() {
return "reset_app_prefs";
}
@Override
public void onCreate(Bundle savedInstanceState) {
mResetAppsHelper.onRestoreInstanceState(savedInstanceState);
}
@Override
public void onSaveInstanceState(Bundle outState) {
mResetAppsHelper.onSaveInstanceState(outState);
}
}

View File

@@ -0,0 +1,157 @@
/*
* Copyright (C) 2015 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.manageapplications;
import static android.net.NetworkPolicyManager.POLICY_NONE;
import static android.net.NetworkPolicyManager.POLICY_REJECT_METERED_BACKGROUND;
import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.AppOpsManager;
import android.app.INotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.net.NetworkPolicyManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.webkit.IWebViewUpdateService;
import com.android.settings.R;
import java.util.List;
public class ResetAppsHelper implements DialogInterface.OnClickListener,
DialogInterface.OnDismissListener {
private static final String EXTRA_RESET_DIALOG = "resetDialog";
private final PackageManager mPm;
private final IPackageManager mIPm;
private final INotificationManager mNm;
private final IWebViewUpdateService mWvus;
private final NetworkPolicyManager mNpm;
private final AppOpsManager mAom;
private final Context mContext;
private AlertDialog mResetDialog;
public ResetAppsHelper(Context context) {
mContext = context;
mPm = context.getPackageManager();
mIPm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
mNm = INotificationManager.Stub.asInterface(
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
mWvus = IWebViewUpdateService.Stub.asInterface(ServiceManager.getService("webviewupdate"));
mNpm = NetworkPolicyManager.from(context);
mAom = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
}
public void onRestoreInstanceState(Bundle savedInstanceState) {
if (savedInstanceState != null && savedInstanceState.getBoolean(EXTRA_RESET_DIALOG)) {
buildResetDialog();
}
}
public void onSaveInstanceState(Bundle outState) {
if (mResetDialog != null) {
outState.putBoolean(EXTRA_RESET_DIALOG, true);
}
}
public void stop() {
if (mResetDialog != null) {
mResetDialog.dismiss();
mResetDialog = null;
}
}
void buildResetDialog() {
if (mResetDialog == null) {
mResetDialog = new AlertDialog.Builder(mContext)
.setTitle(R.string.reset_app_preferences_title)
.setMessage(R.string.reset_app_preferences_desc)
.setPositiveButton(R.string.reset_app_preferences_button, this)
.setNegativeButton(R.string.cancel, null)
.setOnDismissListener(this)
.show();
}
}
@Override
public void onDismiss(DialogInterface dialog) {
if (mResetDialog == dialog) {
mResetDialog = null;
}
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (mResetDialog != dialog) {
return;
}
AsyncTask.execute(new Runnable() {
@Override
public void run() {
List<ApplicationInfo> apps = mPm.getInstalledApplications(
PackageManager.GET_DISABLED_COMPONENTS);
for (int i = 0; i < apps.size(); i++) {
ApplicationInfo app = apps.get(i);
try {
mNm.setNotificationsEnabledForPackage(app.packageName, app.uid, true);
} catch (android.os.RemoteException ex) {
}
if (!app.enabled) {
if (mPm.getApplicationEnabledSetting(app.packageName)
== PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
&& !isNonEnableableFallback(app.packageName)) {
mPm.setApplicationEnabledSetting(app.packageName,
PackageManager.COMPONENT_ENABLED_STATE_DEFAULT,
PackageManager.DONT_KILL_APP);
}
}
}
try {
mIPm.resetApplicationPreferences(UserHandle.myUserId());
} catch (RemoteException e) {
}
mAom.resetAllModes();
final int[] restrictedUids = mNpm.getUidsWithPolicy(
POLICY_REJECT_METERED_BACKGROUND);
final int currentUserId = ActivityManager.getCurrentUser();
for (int uid : restrictedUids) {
// Only reset for current user
if (UserHandle.getUserId(uid) == currentUserId) {
mNpm.setUidPolicy(uid, POLICY_NONE);
}
}
}
});
}
private boolean isNonEnableableFallback(String packageName) {
try {
return mWvus.isFallbackPackage(packageName);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}