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.view.WindowManager;
31 import android.widget.Toast;
32 
33 import com.android.settings.R;
34 import com.android.settings.Utils;
35 
36 public class StorageWizardMigrateProgress extends StorageWizardBase {
37     private static final String TAG = "StorageWizardMigrateProgress";
38 
39     private static final String ACTION_FINISH_WIZARD = "com.android.systemui.action.FINISH_WIZARD";
40 
41     private int mMoveId;
42 
43     @Override
onCreate(Bundle savedInstanceState)44     protected void onCreate(Bundle savedInstanceState) {
45         super.onCreate(savedInstanceState);
46         if (mVolume == null) {
47             finish();
48             return;
49         }
50         setContentView(R.layout.storage_wizard_progress);
51 
52         // hide the navigation bar for this activity only. So that user can not press back button accidentally.
53         View decorView = getWindow().getDecorView();
54         int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
55         decorView.setSystemUiVisibility(uiOptions);
56 
57         //disable touch in activity so user can not make the hidden navigation bar visible.
58         getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
59                      WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
60 
61         mMoveId = getIntent().getIntExtra(EXTRA_MOVE_ID, -1);
62 
63         setIcon(R.drawable.ic_swap_horiz);
64         setHeaderText(R.string.storage_wizard_migrate_progress_v2_title);
65         setAuxChecklist();
66         setBackButtonVisibility(View.INVISIBLE);
67         setNextButtonVisibility(View.INVISIBLE);
68         // Register for updates and push through current status
69         getPackageManager().registerMoveCallback(mCallback, new Handler());
70         mCallback.onStatusChanged(mMoveId, getPackageManager().getMoveStatus(mMoveId), -1);
71     }
72 
73     private final MoveCallback mCallback = new MoveCallback() {
74         @Override
75         public void onStatusChanged(int moveId, int status, long estMillis) {
76             if (mMoveId != moveId) return;
77 
78             final Context context = StorageWizardMigrateProgress.this;
79             if (PackageManager.isMoveStatusFinished(status)) {
80                 Log.d(TAG, "Finished with status " + status);
81                 if (status == PackageManager.MOVE_SUCCEEDED) {
82                     if (mDisk != null) {
83                         // Kinda lame, but tear down that shiny finished
84                         // notification, since user is still in wizard flow
85                         final Intent finishIntent = new Intent(ACTION_FINISH_WIZARD);
86                         finishIntent.setPackage(Utils.SYSTEMUI_PACKAGE_NAME);
87                         finishIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
88                         sendBroadcast(finishIntent);
89 
90                         if (!StorageWizardMigrateProgress.this.isFinishing()) {
91                             final Intent intent = new Intent(context, StorageWizardReady.class);
92                             intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
93                             startActivity(intent);
94                         }
95                     }
96                 } else {
97                     Toast.makeText(context, getString(R.string.insufficient_storage),
98                             Toast.LENGTH_LONG).show();
99                 }
100                 finishAffinity();
101 
102             } else {
103                 setCurrentProgress(status);
104             }
105         }
106     };
107 }
108