Home | History | Annotate | Download | only in plugins
      1 /*
      2  * Copyright (C) 2018 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.plugins;
     16 
     17 import android.content.Context;
     18 import android.os.Looper;
     19 import android.util.Log;
     20 
     21 import com.android.systemui.Dependency;
     22 import com.android.systemui.R;
     23 import com.android.systemui.shared.plugins.PluginEnabler;
     24 import com.android.systemui.shared.plugins.PluginInitializer;
     25 import com.android.systemui.shared.plugins.PluginManagerImpl;
     26 
     27 public class PluginInitializerImpl implements PluginInitializer {
     28 
     29     /**
     30      * True if WTFs should lead to crashes
     31      */
     32     private static final boolean WTFS_SHOULD_CRASH = false;
     33     private boolean mWtfsSet;
     34 
     35     @Override
     36     public Looper getBgLooper() {
     37         return Dependency.get(Dependency.BG_LOOPER);
     38     }
     39 
     40     @Override
     41     public void onPluginManagerInit() {
     42         // Plugin dependencies that don't have another good home can go here, but
     43         // dependencies that have better places to init can happen elsewhere.
     44         Dependency.get(PluginDependencyProvider.class)
     45                 .allowPluginDependency(ActivityStarter.class);
     46     }
     47 
     48     @Override
     49     public String[] getWhitelistedPlugins(Context context) {
     50         return context.getResources().getStringArray(R.array.config_pluginWhitelist);
     51     }
     52 
     53     public PluginEnabler getPluginEnabler(Context context) {
     54         return new PluginEnablerImpl(context);
     55     }
     56 
     57     @Override
     58     public void handleWtfs() {
     59         if (WTFS_SHOULD_CRASH && !mWtfsSet) {
     60             mWtfsSet = true;
     61             Log.setWtfHandler(new Log.TerribleFailureHandler() {
     62                 @Override
     63                 public void onTerribleFailure(String tag, Log.TerribleFailure what,
     64                         boolean system) {
     65                     throw new PluginManagerImpl.CrashWhilePluginActiveException(what);
     66                 }
     67             });
     68         }
     69     }
     70 }
     71