@@ -352,11 +352,6 @@ private void onCallbackDied(int pid) {
352352
353353 @ Override // Binder call
354354 public void scanWifiDisplays () {
355- if (mContext .checkCallingPermission (android .Manifest .permission .CONFIGURE_WIFI_DISPLAY )
356- != PackageManager .PERMISSION_GRANTED ) {
357- throw new SecurityException ("Requires CONFIGURE_WIFI_DISPLAY permission" );
358- }
359-
360355 final long token = Binder .clearCallingIdentity ();
361356 try {
362357 synchronized (mSyncRoot ) {
@@ -371,19 +366,16 @@ public void scanWifiDisplays() {
371366
372367 @ Override // Binder call
373368 public void connectWifiDisplay (String address ) {
374- if (mContext .checkCallingPermission (android .Manifest .permission .CONFIGURE_WIFI_DISPLAY )
375- != PackageManager .PERMISSION_GRANTED ) {
376- throw new SecurityException ("Requires CONFIGURE_WIFI_DISPLAY permission" );
377- }
378369 if (address == null ) {
379370 throw new IllegalArgumentException ("address must not be null" );
380371 }
381372
373+ final boolean trusted = canCallerConfigureWifiDisplay ();
382374 final long token = Binder .clearCallingIdentity ();
383375 try {
384376 synchronized (mSyncRoot ) {
385377 if (mWifiDisplayAdapter != null ) {
386- mWifiDisplayAdapter .requestConnectLocked (address );
378+ mWifiDisplayAdapter .requestConnectLocked (address , trusted );
387379 }
388380 }
389381 } finally {
@@ -393,11 +385,6 @@ public void connectWifiDisplay(String address) {
393385
394386 @ Override // Binder call
395387 public void disconnectWifiDisplay () {
396- if (mContext .checkCallingPermission (android .Manifest .permission .CONFIGURE_WIFI_DISPLAY )
397- != PackageManager .PERMISSION_GRANTED ) {
398- throw new SecurityException ("Requires CONFIGURE_WIFI_DISPLAY permission" );
399- }
400-
401388 final long token = Binder .clearCallingIdentity ();
402389 try {
403390 synchronized (mSyncRoot ) {
@@ -412,13 +399,13 @@ public void disconnectWifiDisplay() {
412399
413400 @ Override // Binder call
414401 public void renameWifiDisplay (String address , String alias ) {
415- if (mContext .checkCallingPermission (android .Manifest .permission .CONFIGURE_WIFI_DISPLAY )
416- != PackageManager .PERMISSION_GRANTED ) {
417- throw new SecurityException ("Requires CONFIGURE_WIFI_DISPLAY permission" );
418- }
419402 if (address == null ) {
420403 throw new IllegalArgumentException ("address must not be null" );
421404 }
405+ if (!canCallerConfigureWifiDisplay ()) {
406+ throw new SecurityException ("Requires CONFIGURE_WIFI_DISPLAY permission to "
407+ + "rename a wifi display." );
408+ }
422409
423410 final long token = Binder .clearCallingIdentity ();
424411 try {
@@ -434,13 +421,13 @@ public void renameWifiDisplay(String address, String alias) {
434421
435422 @ Override // Binder call
436423 public void forgetWifiDisplay (String address ) {
437- if (mContext .checkCallingPermission (android .Manifest .permission .CONFIGURE_WIFI_DISPLAY )
438- != PackageManager .PERMISSION_GRANTED ) {
439- throw new SecurityException ("Requires CONFIGURE_WIFI_DISPLAY permission" );
440- }
441424 if (address == null ) {
442425 throw new IllegalArgumentException ("address must not be null" );
443426 }
427+ if (!canCallerConfigureWifiDisplay ()) {
428+ throw new SecurityException ("Requires CONFIGURE_WIFI_DISPLAY permission to "
429+ + "forget a wifi display." );
430+ }
444431
445432 final long token = Binder .clearCallingIdentity ();
446433 try {
@@ -456,11 +443,6 @@ public void forgetWifiDisplay(String address) {
456443
457444 @ Override // Binder call
458445 public WifiDisplayStatus getWifiDisplayStatus () {
459- if (mContext .checkCallingPermission (android .Manifest .permission .CONFIGURE_WIFI_DISPLAY )
460- != PackageManager .PERMISSION_GRANTED ) {
461- throw new SecurityException ("Requires CONFIGURE_WIFI_DISPLAY permission" );
462- }
463-
464446 final long token = Binder .clearCallingIdentity ();
465447 try {
466448 synchronized (mSyncRoot ) {
@@ -475,6 +457,11 @@ public WifiDisplayStatus getWifiDisplayStatus() {
475457 }
476458 }
477459
460+ private boolean canCallerConfigureWifiDisplay () {
461+ return mContext .checkCallingPermission (android .Manifest .permission .CONFIGURE_WIFI_DISPLAY )
462+ == PackageManager .PERMISSION_GRANTED ;
463+ }
464+
478465 private void registerDefaultDisplayAdapter () {
479466 // Register default display adapter.
480467 synchronized (mSyncRoot ) {
0 commit comments