| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.view.displayhash; |
| 18 |
|
| 19 |
|
| 20 |
import static android.content.Context.DISPLAY_HASH_SERVICE; |
| 21 |
|
| 22 |
import android.annotation.NonNull; |
| 23 |
import android.annotation.Nullable; |
| 24 |
import android.annotation.RequiresPermission; |
| 25 |
import android.annotation.SystemService; |
| 26 |
import android.annotation.TestApi; |
| 27 |
import android.os.RemoteException; |
| 28 |
import android.util.ArraySet; |
| 29 |
import android.util.Log; |
| 30 |
import android.view.WindowManagerGlobal; |
| 31 |
|
| 32 |
import com.android.internal.annotations.GuardedBy; |
| 33 |
|
| 34 |
import java.util.Collections; |
| 35 |
import java.util.Set; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
@SystemService(DISPLAY_HASH_SERVICE) |
| 42 |
public final class DisplayHashManager { |
| 43 |
private static final String TAG = "DisplayHashManager"; |
| 44 |
|
| 45 |
private final Object mSupportedHashingAlgorithmLock = new Object(); |
| 46 |
|
| 47 |
@GuardedBy("mSupportedAlgorithmLock") |
| 48 |
private static Set<String> sSupportedHashAlgorithms; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public DisplayHashManager() { |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
@NonNull |
| 63 |
public Set<String> getSupportedHashAlgorithms() { |
| 64 |
synchronized (mSupportedHashingAlgorithmLock) { |
| 65 |
if (sSupportedHashAlgorithms != null) { |
| 66 |
return sSupportedHashAlgorithms; |
| 67 |
} |
| 68 |
|
| 69 |
try { |
| 70 |
String[] supportedAlgorithms = WindowManagerGlobal.getWindowManagerService() |
| 71 |
.getSupportedDisplayHashAlgorithms(); |
| 72 |
if (supportedAlgorithms == null) { |
| 73 |
return Collections.emptySet(); |
| 74 |
} |
| 75 |
sSupportedHashAlgorithms = new ArraySet<>(supportedAlgorithms); |
| 76 |
return sSupportedHashAlgorithms; |
| 77 |
} catch (RemoteException e) { |
| 78 |
Log.e(TAG, "Failed to send request getSupportedHashingAlgorithms", e); |
| 79 |
throw e.rethrowFromSystemServer(); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
@Nullable |
| 92 |
public VerifiedDisplayHash verifyDisplayHash(@NonNull DisplayHash displayHash) { |
| 93 |
try { |
| 94 |
return WindowManagerGlobal.getWindowManagerService().verifyDisplayHash(displayHash); |
| 95 |
} catch (RemoteException e) { |
| 96 |
Log.e(TAG, "Failed to send request verifyImpressionToken", e); |
| 97 |
throw e.rethrowFromSystemServer(); |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
@TestApi |
| 108 |
@RequiresPermission(android.Manifest.permission.READ_FRAME_BUFFER) |
| 109 |
public void setDisplayHashThrottlingEnabled(boolean enable) { |
| 110 |
try { |
| 111 |
WindowManagerGlobal.getWindowManagerService().setDisplayHashThrottlingEnabled(enable); |
| 112 |
} catch (RemoteException e) { |
| 113 |
} |
| 114 |
} |
| 115 |
} |