Home | History | Annotate | Download | only in systemui
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
      5  * except in compliance with the License. You may obtain a copy of the License at
      6  *
      7  *      http://www.apache.org/licenses/LICENSE-2.0
      8  *
      9  * Unless required by applicable law or agreed to in writing, software distributed under the
     10  * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     11  * KIND, either express or implied. See the License for the specific language governing
     12  * permissions and limitations under the License.
     13  */
     14 
     15 package com.android.systemui;
     16 
     17 import android.app.PendingIntent;
     18 import android.content.Intent;
     19 import android.view.View;
     20 
     21 import com.android.systemui.plugins.ActivityStarter;
     22 
     23 import javax.inject.Inject;
     24 import javax.inject.Singleton;
     25 
     26 /**
     27  * Single common instance of ActivityStarter that can be gotten and referenced from anywhere, but
     28  * delegates to an actual implementation such as StatusBar, assuming it exists.
     29  */
     30 @Singleton
     31 public class ActivityStarterDelegate implements ActivityStarter {
     32 
     33     private ActivityStarter mActualStarter;
     34 
     35     @Inject
     36     public ActivityStarterDelegate() {
     37     }
     38 
     39     @Override
     40     public void startPendingIntentDismissingKeyguard(PendingIntent intent) {
     41         if (mActualStarter == null) {
     42             return;
     43         }
     44         mActualStarter.startPendingIntentDismissingKeyguard(intent);
     45     }
     46 
     47     @Override
     48     public void startPendingIntentDismissingKeyguard(PendingIntent intent,
     49             Runnable intentSentCallback) {
     50         if (mActualStarter == null) {
     51             return;
     52         }
     53         mActualStarter.startPendingIntentDismissingKeyguard(intent, intentSentCallback);
     54     }
     55 
     56     @Override
     57     public void startPendingIntentDismissingKeyguard(PendingIntent intent,
     58             Runnable intentSentCallback, View associatedView) {
     59         if (mActualStarter == null) {
     60             return;
     61         }
     62         mActualStarter.startPendingIntentDismissingKeyguard(intent, intentSentCallback,
     63                 associatedView);
     64     }
     65 
     66     @Override
     67     public void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade,
     68             int flags) {
     69         if (mActualStarter == null) {
     70             return;
     71         }
     72         mActualStarter.startActivity(intent, onlyProvisioned, dismissShade, flags);
     73     }
     74 
     75     @Override
     76     public void startActivity(Intent intent, boolean dismissShade) {
     77         if (mActualStarter == null) {
     78             return;
     79         }
     80         mActualStarter.startActivity(intent, dismissShade);
     81     }
     82 
     83     @Override
     84     public void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade) {
     85         if (mActualStarter == null) {
     86             return;
     87         }
     88         mActualStarter.startActivity(intent, onlyProvisioned, dismissShade);
     89     }
     90 
     91     @Override
     92     public void startActivity(Intent intent, boolean dismissShade, Callback callback) {
     93         if (mActualStarter == null) {
     94             return;
     95         }
     96         mActualStarter.startActivity(intent, dismissShade, callback);
     97     }
     98 
     99     @Override
    100     public void postStartActivityDismissingKeyguard(Intent intent, int delay) {
    101         if (mActualStarter == null) {
    102             return;
    103         }
    104         mActualStarter.postStartActivityDismissingKeyguard(intent, delay);
    105     }
    106 
    107     @Override
    108     public void postStartActivityDismissingKeyguard(PendingIntent intent) {
    109         if (mActualStarter == null) {
    110             return;
    111         }
    112         mActualStarter.postStartActivityDismissingKeyguard(intent);
    113     }
    114 
    115     @Override
    116     public void postQSRunnableDismissingKeyguard(Runnable runnable) {
    117         if (mActualStarter == null) {
    118             return;
    119         }
    120         mActualStarter.postQSRunnableDismissingKeyguard(runnable);
    121     }
    122 
    123     @Override
    124     public void dismissKeyguardThenExecute(OnDismissAction action, Runnable cancel,
    125             boolean afterKeyguardGone) {
    126         if (mActualStarter == null) {
    127             return;
    128         }
    129         mActualStarter.dismissKeyguardThenExecute(action, cancel, afterKeyguardGone);
    130     }
    131 
    132     public void setActivityStarterImpl(ActivityStarter starter) {
    133         mActualStarter = starter;
    134     }
    135 }
    136