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 static android.content.pm.PackageManager.EXTRA_MOVE_ID; 20 21 import android.content.Context; 22 import android.content.Intent; 23 import android.content.pm.PackageManager; 24 import android.content.pm.PackageManager.MoveCallback; 25 import android.os.Bundle; 26 import android.os.Handler; 27 import android.os.storage.DiskInfo; 28 import android.util.Log; 29 import android.view.View; 30 import android.widget.Toast; 31 32 import com.android.settings.R; 33 34 public class StorageWizardMigrateProgress extends StorageWizardBase { 35 private static final String TAG = "StorageWizardMigrateProgress"; 36 37 private static final String ACTION_FINISH_WIZARD = "com.android.systemui.action.FINISH_WIZARD"; 38 39 private int mMoveId; 40 41 @Override onCreate(Bundle savedInstanceState)42 protected void onCreate(Bundle savedInstanceState) { 43 super.onCreate(savedInstanceState); 44 if (mVolume == null) { 45 finish(); 46 return; 47 } 48 setContentView(R.layout.storage_wizard_progress); 49 50 mMoveId = getIntent().getIntExtra(EXTRA_MOVE_ID, -1); 51 52 setIcon(R.drawable.ic_swap_horiz); 53 setHeaderText(R.string.storage_wizard_migrate_progress_v2_title); 54 setAuxChecklist(); 55 setBackButtonVisibility(View.INVISIBLE); 56 setNextButtonVisibility(View.INVISIBLE); 57 // Register for updates and push through current status 58 getPackageManager().registerMoveCallback(mCallback, new Handler()); 59 mCallback.onStatusChanged(mMoveId, getPackageManager().getMoveStatus(mMoveId), -1); 60 } 61 62 private final MoveCallback mCallback = new MoveCallback() { 63 @Override 64 public void onStatusChanged(int moveId, int status, long estMillis) { 65 if (mMoveId != moveId) return; 66 67 final Context context = StorageWizardMigrateProgress.this; 68 if (PackageManager.isMoveStatusFinished(status)) { 69 Log.d(TAG, "Finished with status " + status); 70 if (status == PackageManager.MOVE_SUCCEEDED) { 71 if (mDisk != null) { 72 // Kinda lame, but tear down that shiny finished 73 // notification, since user is still in wizard flow 74 final Intent finishIntent = new Intent(ACTION_FINISH_WIZARD); 75 finishIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); 76 sendBroadcast(finishIntent); 77 78 if (!StorageWizardMigrateProgress.this.isFinishing()) { 79 final Intent intent = new Intent(context, StorageWizardReady.class); 80 intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId()); 81 startActivity(intent); 82 } 83 } 84 } else { 85 Toast.makeText(context, getString(R.string.insufficient_storage), 86 Toast.LENGTH_LONG).show(); 87 } 88 finishAffinity(); 89 90 } else { 91 setCurrentProgress(status); 92 } 93 } 94 }; 95 } 96