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