1 /* 2 * Copyright (C) 2017 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.net; 18 19 import android.annotation.Nullable; 20 import android.annotation.SystemApi; 21 import android.annotation.SystemService; 22 import android.annotation.TestApi; 23 import android.content.Context; 24 import android.os.RemoteException; 25 import android.os.ServiceManager; 26 import android.util.Log; 27 28 import com.android.internal.net.INetworkWatchlistManager; 29 import com.android.internal.util.Preconditions; 30 31 /** 32 * Class that manage network watchlist in system. 33 * @hide 34 */ 35 @TestApi 36 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 37 @SystemService(Context.NETWORK_WATCHLIST_SERVICE) 38 public class NetworkWatchlistManager { 39 40 private static final String TAG = "NetworkWatchlistManager"; 41 private static final String SHARED_MEMORY_TAG = "NETWORK_WATCHLIST_SHARED_MEMORY"; 42 43 private final Context mContext; 44 private final INetworkWatchlistManager mNetworkWatchlistManager; 45 46 /** 47 * @hide 48 */ NetworkWatchlistManager(Context context, INetworkWatchlistManager manager)49 public NetworkWatchlistManager(Context context, INetworkWatchlistManager manager) { 50 mContext = context; 51 mNetworkWatchlistManager = manager; 52 } 53 54 /** 55 * @hide 56 */ NetworkWatchlistManager(Context context)57 public NetworkWatchlistManager(Context context) { 58 mContext = Preconditions.checkNotNull(context, "missing context"); 59 mNetworkWatchlistManager = (INetworkWatchlistManager) 60 INetworkWatchlistManager.Stub.asInterface( 61 ServiceManager.getService(Context.NETWORK_WATCHLIST_SERVICE)); 62 } 63 64 /** 65 * Report network watchlist records if necessary. 66 * 67 * Watchlist report process will summarize records into a single report, then the 68 * report will be processed by differential privacy framework and stored on disk. 69 * 70 * @hide 71 */ reportWatchlistIfNecessary()72 public void reportWatchlistIfNecessary() { 73 try { 74 mNetworkWatchlistManager.reportWatchlistIfNecessary(); 75 } catch (RemoteException e) { 76 Log.e(TAG, "Cannot report records", e); 77 e.rethrowFromSystemServer(); 78 } 79 } 80 81 /** 82 * Reload network watchlist. 83 * 84 * @hide 85 */ reloadWatchlist()86 public void reloadWatchlist() { 87 try { 88 mNetworkWatchlistManager.reloadWatchlist(); 89 } catch (RemoteException e) { 90 Log.e(TAG, "Unable to reload watchlist"); 91 e.rethrowFromSystemServer(); 92 } 93 } 94 95 /** 96 * Get Network Watchlist config file hash. 97 */ 98 @Nullable getWatchlistConfigHash()99 public byte[] getWatchlistConfigHash() { 100 try { 101 return mNetworkWatchlistManager.getWatchlistConfigHash(); 102 } catch (RemoteException e) { 103 Log.e(TAG, "Unable to get watchlist config hash"); 104 throw e.rethrowFromSystemServer(); 105 } 106 } 107 } 108