Home | History | Annotate | Download | only in deviceinfo
      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.Context;
     20 import android.content.Intent;
     21 import android.content.pm.PackageManager;
     22 import android.content.pm.PackageManager.MoveCallback;
     23 import android.os.Bundle;
     24 import android.os.Handler;
     25 import android.os.storage.DiskInfo;
     26 import android.util.Log;
     27 import android.view.View;
     28 import android.widget.Toast;
     29 
     30 import com.android.settings.R;
     31 
     32 import static android.content.pm.PackageManager.EXTRA_MOVE_ID;
     33 import static com.android.settings.deviceinfo.StorageSettings.TAG;
     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
     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         final String descrip = mStorage.getBestVolumeDescription(mVolume);
     52         setIllustrationType(ILLUSTRATION_INTERNAL);
     53         setHeaderText(R.string.storage_wizard_migrate_progress_title, descrip);
     54         setBodyText(R.string.storage_wizard_migrate_details, descrip);
     55 
     56         getNextButton().setVisibility(View.GONE);
     57 
     58         // Register for updates and push through current status
     59         getPackageManager().registerMoveCallback(mCallback, new Handler());
     60         mCallback.onStatusChanged(mMoveId, getPackageManager().getMoveStatus(mMoveId), -1);
     61     }
     62 
     63     private final MoveCallback mCallback = new MoveCallback() {
     64         @Override
     65         public void onStatusChanged(int moveId, int status, long estMillis) {
     66             if (mMoveId != moveId) return;
     67 
     68             final Context context = StorageWizardMigrateProgress.this;
     69             if (PackageManager.isMoveStatusFinished(status)) {
     70                 Log.d(TAG, "Finished with status " + status);
     71                 if (status == PackageManager.MOVE_SUCCEEDED) {
     72                     if (mDisk != null) {
     73                         // Kinda lame, but tear down that shiny finished
     74                         // notification, since user is still in wizard flow
     75                         final Intent finishIntent = new Intent(ACTION_FINISH_WIZARD);
     76                         finishIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
     77                         sendBroadcast(finishIntent);
     78 
     79                         if (!StorageWizardMigrateProgress.this.isFinishing()) {
     80                             final Intent intent = new Intent(context, StorageWizardReady.class);
     81                             intent.putExtra(DiskInfo.EXTRA_DISK_ID, mDisk.getId());
     82                             startActivity(intent);
     83                         }
     84                     }
     85                 } else {
     86                     Toast.makeText(context, getString(R.string.insufficient_storage),
     87                             Toast.LENGTH_LONG).show();
     88                 }
     89                 finishAffinity();
     90 
     91             } else {
     92                 setCurrentProgress(status);
     93             }
     94         }
     95     };
     96 }
     97