1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.deviceinfo; 18 19 import android.content.pm.PackageManager; 20 import android.content.pm.PackageManager.MoveCallback; 21 import android.os.Bundle; 22 import android.os.Handler; 23 import android.util.Log; 24 import android.view.View; 25 import android.widget.Toast; 26 27 import com.android.settings.R; 28 29 import static android.content.Intent.EXTRA_TITLE; 30 import static android.content.pm.PackageManager.EXTRA_MOVE_ID; 31 import static com.android.settings.deviceinfo.StorageSettings.TAG; 32 33 public class StorageWizardMoveProgress extends StorageWizardBase { 34 private int mMoveId; 35 36 @Override 37 protected void onCreate(Bundle savedInstanceState) { 38 super.onCreate(savedInstanceState); 39 if (mVolume == null) { 40 finish(); 41 return; 42 } 43 setContentView(R.layout.storage_wizard_progress); 44 45 mMoveId = getIntent().getIntExtra(EXTRA_MOVE_ID, -1); 46 final String appName = getIntent().getStringExtra(EXTRA_TITLE); 47 final String volumeName = mStorage.getBestVolumeDescription(mVolume); 48 49 setIcon(R.drawable.ic_swap_horiz); 50 setHeaderText(R.string.storage_wizard_move_progress_title, appName); 51 setBodyText(R.string.storage_wizard_move_progress_body, volumeName, appName); 52 53 // Register for updates and push through current status 54 getPackageManager().registerMoveCallback(mCallback, new Handler()); 55 mCallback.onStatusChanged(mMoveId, getPackageManager().getMoveStatus(mMoveId), -1); 56 } 57 58 @Override 59 protected void onDestroy() { 60 super.onDestroy(); 61 getPackageManager().unregisterMoveCallback(mCallback); 62 } 63 64 private final MoveCallback mCallback = new MoveCallback() { 65 @Override 66 public void onStatusChanged(int moveId, int status, long estMillis) { 67 if (mMoveId != moveId) return; 68 69 if (PackageManager.isMoveStatusFinished(status)) { 70 Log.d(TAG, "Finished with status " + status); 71 if (status != PackageManager.MOVE_SUCCEEDED) { 72 Toast.makeText(StorageWizardMoveProgress.this, moveStatusToMessage(status), 73 Toast.LENGTH_LONG).show(); 74 } 75 finishAffinity(); 76 77 } else { 78 setCurrentProgress(status); 79 } 80 } 81 }; 82 83 private CharSequence moveStatusToMessage(int returnCode) { 84 switch (returnCode) { 85 case PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE: 86 return getString(R.string.insufficient_storage); 87 case PackageManager.MOVE_FAILED_DEVICE_ADMIN: 88 return getString(R.string.move_error_device_admin); 89 case PackageManager.MOVE_FAILED_DOESNT_EXIST: 90 return getString(R.string.does_not_exist); 91 case PackageManager.MOVE_FAILED_FORWARD_LOCKED: 92 return getString(R.string.app_forward_locked); 93 case PackageManager.MOVE_FAILED_INVALID_LOCATION: 94 return getString(R.string.invalid_location); 95 case PackageManager.MOVE_FAILED_SYSTEM_PACKAGE: 96 return getString(R.string.system_package); 97 case PackageManager.MOVE_FAILED_INTERNAL_ERROR: 98 default: 99 return getString(R.string.insufficient_storage); 100 } 101 } 102 } 103