1 /* 2 * Copyright (C) 2019 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 package com.android.cts.mainlinemoduledetector; 17 18 import android.app.Activity; 19 import android.content.pm.PackageManager; 20 import android.os.Bundle; 21 import android.util.Log; 22 23 import com.android.compatibility.common.util.mainline.MainlineModule; 24 import com.android.compatibility.common.util.mainline.ModuleDetector; 25 26 import java.util.HashSet; 27 import java.util.Set; 28 29 public class MainlineModuleDetector extends Activity { 30 31 private static final String LOG_TAG = "MainlineModuleDetector"; 32 33 @Override onCreate(Bundle savedInstanceState)34 public void onCreate(Bundle savedInstanceState) { 35 super.onCreate(savedInstanceState); 36 try { 37 PackageManager pm = getApplicationContext().getPackageManager(); 38 Set<MainlineModule> modules = ModuleDetector.getPlayManagedModules(pm); 39 Set<String> moduleNames = new HashSet<>(); 40 for (MainlineModule module : modules) { 41 moduleNames.add(module.packageName); 42 } 43 Log.i(LOG_TAG, "Play managed modules are: <" + String.join(",", moduleNames) + ">"); 44 } catch (Exception e) { 45 Log.e(LOG_TAG, "Failed to retrieve modules.", e); 46 } 47 this.finish(); 48 } 49 } 50