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 android.app;
18 
19 import android.annotation.SystemApi;
20 import android.app.Service;
21 import android.app.InstantAppResolverService.InstantAppResolutionCallback;
22 import android.content.Context;
23 import android.content.Intent;
24 import android.content.pm.EphemeralResolveInfo;
25 import android.content.pm.InstantAppResolveInfo;
26 import android.os.Build;
27 import android.os.Bundle;
28 import android.os.Handler;
29 import android.os.IBinder;
30 import android.os.IRemoteCallback;
31 import android.os.Looper;
32 import android.os.Message;
33 import android.os.RemoteException;
34 import android.util.Log;
35 
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.List;
39 
40 /**
41  * Base class for implementing the resolver service.
42  * @hide
43  * @deprecated use InstantAppResolverService instead
44  */
45 @Deprecated
46 @SystemApi
47 public abstract class EphemeralResolverService extends InstantAppResolverService {
48     private static final boolean DEBUG_EPHEMERAL = Build.IS_DEBUGGABLE;
49     private static final String TAG = "PackageManager";
50 
51     /**
52      * Called to retrieve resolve info for ephemeral applications.
53      *
54      * @param digestPrefix The hash prefix of the ephemeral's domain.
55      * @param prefixMask A mask that was applied to each digest prefix. This should
56      *      be used when comparing against the digest prefixes as all bits might
57      *      not be set.
58      * @deprecated use {@link #onGetEphemeralResolveInfo(int[])} instead
59      */
60     @Deprecated
onEphemeralResolveInfoList( int digestPrefix[], int prefix)61     public abstract List<EphemeralResolveInfo> onEphemeralResolveInfoList(
62             int digestPrefix[], int prefix);
63 
64     /**
65      * Called to retrieve resolve info for ephemeral applications.
66      *
67      * @param digestPrefix The hash prefix of the ephemeral's domain.
68      */
onGetEphemeralResolveInfo(int digestPrefix[])69     public List<EphemeralResolveInfo> onGetEphemeralResolveInfo(int digestPrefix[]) {
70         return onEphemeralResolveInfoList(digestPrefix, 0xFFFFF000);
71     }
72 
73     /**
74      * Called to retrieve intent filters for ephemeral applications.
75      *
76      * @param hostName The name of the host to get intent filters for.
77      */
onGetEphemeralIntentFilter(String hostName)78     public EphemeralResolveInfo onGetEphemeralIntentFilter(String hostName) {
79         throw new IllegalStateException("Must define");
80     }
81 
82     @Override
getLooper()83     public Looper getLooper() {
84         return super.getLooper();
85     }
86 
87     @Override
_onGetInstantAppResolveInfo(int[] digestPrefix, String token, InstantAppResolutionCallback callback)88     void _onGetInstantAppResolveInfo(int[] digestPrefix, String token,
89             InstantAppResolutionCallback callback) {
90         if (DEBUG_EPHEMERAL) {
91             Log.d(TAG, "Legacy resolver; getInstantAppResolveInfo;"
92                     + " prefix: " + Arrays.toString(digestPrefix));
93         }
94         final List<EphemeralResolveInfo> response = onGetEphemeralResolveInfo(digestPrefix);
95         final int responseSize = response == null ? 0 : response.size();
96         final List<InstantAppResolveInfo> resultList = new ArrayList<>(responseSize);
97         for (int i = 0; i < responseSize; i++) {
98             resultList.add(response.get(i).getInstantAppResolveInfo());
99         }
100         callback.onInstantAppResolveInfo(resultList);
101     }
102 
103     @Override
_onGetInstantAppIntentFilter(int[] digestPrefix, String token, String hostName, InstantAppResolutionCallback callback)104     void _onGetInstantAppIntentFilter(int[] digestPrefix, String token,
105             String hostName, InstantAppResolutionCallback callback) {
106         if (DEBUG_EPHEMERAL) {
107             Log.d(TAG, "Legacy resolver; getInstantAppIntentFilter;"
108                     + " prefix: " + Arrays.toString(digestPrefix));
109         }
110         final EphemeralResolveInfo response = onGetEphemeralIntentFilter(hostName);
111         final List<InstantAppResolveInfo> resultList = new ArrayList<>(1);
112         resultList.add(response.getInstantAppResolveInfo());
113         callback.onInstantAppResolveInfo(resultList);
114     }
115 }
116