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.Intent; 20 import android.content.pm.ApplicationInfo; 21 import android.content.pm.PackageManager.NameNotFoundException; 22 import android.os.Bundle; 23 24 import com.android.internal.util.Preconditions; 25 import com.android.settings.R; 26 27 import static android.content.Intent.EXTRA_PACKAGE_NAME; 28 import static android.content.Intent.EXTRA_TITLE; 29 import static android.content.pm.PackageManager.EXTRA_MOVE_ID; 30 import static android.os.storage.VolumeInfo.EXTRA_VOLUME_ID; 31 32 public class StorageWizardMoveConfirm extends StorageWizardBase { 33 private String mPackageName; 34 private ApplicationInfo mApp; 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_generic); 44 45 try { 46 mPackageName = getIntent().getStringExtra(EXTRA_PACKAGE_NAME); 47 mApp = getPackageManager().getApplicationInfo(mPackageName, 0); 48 } catch (NameNotFoundException e) { 49 finish(); 50 return; 51 } 52 53 // Sanity check that target volume is candidate 54 Preconditions.checkState( 55 getPackageManager().getPackageCandidateVolumes(mApp).contains(mVolume)); 56 57 final String appName = getPackageManager().getApplicationLabel(mApp).toString(); 58 final String volumeName = mStorage.getBestVolumeDescription(mVolume); 59 60 setIllustrationType(ILLUSTRATION_INTERNAL); 61 setHeaderText(R.string.storage_wizard_move_confirm_title, appName); 62 setBodyText(R.string.storage_wizard_move_confirm_body, appName, volumeName); 63 64 getNextButton().setText(R.string.move_app); 65 } 66 67 @Override 68 public void onNavigateNext() { 69 // Kick off move before we transition 70 final String appName = getPackageManager().getApplicationLabel(mApp).toString(); 71 final int moveId = getPackageManager().movePackage(mPackageName, mVolume); 72 73 final Intent intent = new Intent(this, StorageWizardMoveProgress.class); 74 intent.putExtra(EXTRA_MOVE_ID, moveId); 75 intent.putExtra(EXTRA_TITLE, appName); 76 intent.putExtra(EXTRA_VOLUME_ID, mVolume.getId()); 77 startActivity(intent); 78 finishAffinity(); 79 } 80 } 81