• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.tests.loadingprogress.registerapp;
18 
19 import android.app.Activity;
20 import android.content.pm.LauncherApps;
21 import android.os.Bundle;
22 import android.os.Handler;
23 import android.os.UserHandle;
24 import android.util.Log;
25 
26 public class MainActivity extends Activity {
27     private static final String TAG = "RegisterApp";
28     @Override
onCreate(Bundle savedInstanceState)29     public void onCreate(Bundle savedInstanceState)  {
30         super.onCreate(savedInstanceState);
31         LauncherApps.Callback callback = new LauncherApps.Callback() {
32             @Override
33             public void onPackageRemoved(String packageName, UserHandle user) {
34             }
35 
36             @Override
37             public void onPackageAdded(String packageName, UserHandle user) {
38             }
39 
40             @Override
41             public void onPackageChanged(String packageName, UserHandle user) {
42             }
43 
44             @Override
45             public void onPackagesAvailable(String[] packageNames, UserHandle user,
46                     boolean replacing) {
47             }
48 
49             @Override
50             public void onPackagesUnavailable(String[] packageNames, UserHandle user,
51                     boolean replacing) {
52             }
53         };
54         // Register a callback to LauncherApps Service. This is required before the test app is
55         // first installed so that loading progress listener can be activated for the test app.
56         final LauncherApps launcherApps = getApplicationContext().getSystemService(
57                 LauncherApps.class);
58         if (launcherApps != null) {
59             launcherApps.registerCallback(callback, new Handler(getMainLooper()));
60         }
61         Log.i(TAG, "Registered the first callback");
62     }
63 }
64