2016-12-09 5 views
1

기존 APN을 읽으려고하고 나서 내 안드로이드 장치에 custum APN 이름을 써야합니다. 하지만 그것은 내 응용 프로그램을/system/app에 넣고 내 매니페스트에서 사용 권한을 선언하더라도 읽기/쓰기를 허용하지 않습니다. 01 : 17.831 :안드로이드에서 프로그래밍 방식으로 시스템 수준의 사용 권한을 부여하는 방법은 무엇입니까?

오류

이하

15 System.err의 발생 (1717)/W :이 java.lang.SecurityException : 10060 어느 사용자도 현재 프로세스 android.permission.MODIFY_PHONE_STATE있다. 01-01 15 : 01 : 17.832 : W/System.err (1717) : android.os.Parcel.readException (Parcel.java:1620) 01-01 15 : 01 : 17.832 : W/System.err (1717) : android.os.Parcel.readException (Parcel.java:1573) 01-01 15 : 01 : 17.832 : System.err (1717) : com.android.internal.telephony.ITelephony $ Stub $에서 Proxy.supplyPin (ITelephony.java:1775) 01-01 15 : 01 : 17.833 : System.err (1717) : com.intel.sunnypoint.headless.HeadlessService.simUnlock (HeadlessService.java:194) 01 -01 15 : 01 : 17.833 : W/System.err (1717) : com.intel.sunnypoint.headless.HeadlessService.onStartCommand (HeadlessService.java:166) 01-01 15 : 01 : 17.833 : W/System. (1717) : android.app.ActivityThread.handleServiceArgs (ActivityThread.java:3032) 01-01 15 : 01 : 17.833 : W/System.err (1717) : android.app.ActivityThread.access $ 2300 (Acti vityThread.java:150) 01-01 15 : 01 : 17.833 : W/System.err (1717) : android.app.ActivityThread $ H.handleMessage (ActivityThread.java:1455) 01-01 15:01 : 17.833 : W/System.err (1717) : android.os.Handler.dispatchMessage (Handler.java:102) 01-01 15 : 01 : 17.833 : W/System.err (1717) : android.os. Looper.loop (Looper.java:148) 01-01 15 : 01 : 17.833 : W/System.err (1717) : android.app.ActivityThread.main (ActivityThread.java:5446) 01-01 : 01 : 17.833 : W/System.err (1717) : java.lang.reflect.Method.invoke (기본 메서드) 01-01 15 : 01 : 17.833 : System.err (1717) : com.android .internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:749) 01-01 15 : 01 : 17.833 : System.err (1717) : com.android.internal.os.ZygoteInit.main (ZygoteInit .java : 639)

다음은 내 코드

공공 INT InsertAPN (문자열 이름) {

//Set the URIs and variables 
    int id = -1; 
    boolean existing = false; 
    final Uri APN_TABLE_URI = Uri.parse("content://telephony/carriers"); 
    final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn"); 

    //Check if the specified APN is already in the APN table, if so skip the insertion 
    Cursor parser = getContentResolver().query(APN_TABLE_URI, null, null, null, null); 
    parser.moveToLast(); 
    while (parser.isBeforeFirst() == false){ 
     int index = parser.getColumnIndex("name"); 
     String n = parser.getString(index); 
     if (n.equals(name)) { 
      existing = true; 
      Log.d(TAG, "APN already configured."); 
      break; 
     } 
     parser.moveToPrevious(); 
    } 

    //if the entry doesn't already exist, insert it into the APN table 
    if (!existing){ 

     //Initialize the Content Resolver and Content Provider 
     ContentResolver resolver = this.getContentResolver(); 
     ContentValues values = new ContentValues(); 

     //Capture all the existing field values excluding name 
     Cursor apu = getContentResolver().query(PREFERRED_APN_URI, null, null, null, null); 
     apu.moveToFirst(); 


     //Assign them to the ContentValue object 
     values.put("name", name); //the method parameter 
     values.put("apn", "Simple CMW APN"); 
     values.put("type", "default"); 
     values.put("proxy", ""); 
     values.put("port", ""); 
     values.put("user", ""); 
     values.put("password", ""); 
     values.put("server", ""); 
     values.put("mmsc", ""); 
     values.put("mmsproxy", ""); 
     values.put("mmsport", ""); 
     values.put("mcc", "001"); 
     values.put("mnc", "01"); 
     values.put("numeric", ""); 

     //Actual insertion into table 
     Cursor c = null; 
     try{ 
      Uri newRow = resolver.insert(APN_TABLE_URI, values); 

      if(newRow != null){ 
       c = resolver.query(newRow, null, null, null, null); 
       int idindex = c.getColumnIndex("_id"); 
       c.moveToFirst(); 
       id = c.getShort(idindex); 
      } 
     } 
     catch(Exception e){} 
     if(c !=null) c.close(); 
    } 

    return id; 
} 

//Takes the ID of the new record generated in InsertAPN and sets that particular record the default preferred APN configuration 
public boolean SetPreferredAPN(int id){ 

    //If the id is -1, that means the record was found in the APN table before insertion, thus, no action required 
    if (id == -1){ 
     return false; 
    } 

    Uri.parse("content://telephony/carriers"); 
    final Uri PREFERRED_APN_URI = Uri.parse("content://telephony/carriers/preferapn"); 

    boolean res = false; 
    ContentResolver resolver = this.getContentResolver(); 
    ContentValues values = new ContentValues(); 

    values.put("apn_id", id); 
    try{ 
     resolver.update(PREFERRED_APN_URI, values, null, null); 
     Cursor c = resolver.query(PREFERRED_APN_URI, new String[]{"name", "apn"}, "_id="+id, null, null); 
     if(c != null){ 
      res = true; 
      c.close(); 
     } 
    } 
    catch (Exception e){} 
    return res; 
} 

방법을 설정하는 나를 인도 해주십시오이다. 미리 감사드립니다.

+0

루트 액세스 사용 –

답변

0

1.You는 필요를 시행하는 경우 2.You는 안드로이드 매니페스트

3.SELinux 정책의 시스템 UID를 가지고 당신의 응용 프로그램을 필요

을 체결 동일한 키 시스템에서 응용 프로그램을 등록해야 당신의 경우에는 그 문제를 해결할 수있을 것이라고 생각합니다.

+0

안녕하세요, 내 시스템이 서명되었는지 여부를 어떻게 알 수 있습니까? 그래서 (위치)가 동일한 서명 키를 얻기 위해 확인할 수있는 곳이라면? – kodali

+0

고마워,이 일은 나를 위해 일했다. 1. 시스템에 서명 한 것과 같은 방식으로 내 앱에 서명했습니다. 2. 먼저 정상적인 방법으로 설치 한 다음 내 앱을 시스템 앱으로 만듭니다. 3. 그런 다음 장치를 다시 시작합니다. – kodali

0

'위험한'것으로 분류 된 권한의 경우 사용자의 허가를 요청해야합니다. 사용자의 허가를 요청하면이를 구현하지 못합니다. https://developer.android.com/training/permissions/requesting.html

참조하십시오 당신이 알려 :)

+0

HI Nick, 귀중하고 관련성있는 답변을 주셔서 감사합니다. '위험한'권한을 문법적으로 설정하는 방법을 알려주십시오. 나는 문서를 말했지만, 사용자에게 권한을 부여하거나 거부하라는 시스템 대화 상자가 표시되지 않습니다. – kodali

0

당신이 문서를 읽을 경우하자 도움말 설정이 필요하면, 당신은 그것을 볼 수 있습니다

MODIFY_PHONE_STATE을

전원 켜기, mmi 등의 전화 통신 상태를 수정할 수 있습니다. 전화 발신은 포함되지 않습니다.

타사 응용 프로그램에서 사용하지 마십시오.

마지막 줄에주의하십시오. 그것은 시스템에 의해서만 사용될 수있는 허가이며 다른 어플리케이션에 의해서는 사용될 수 없습니다.

시스템 수준 응용 프로그램은 시스템 폴더에 사전 설치되거나 특수한 제조업체의 인증서로 컴파일됩니다. 당신은 /system/app 폴더에 넣었다고 말했지만 뿌리깊은 장치의 사용자 만 귀하의 단계를 반복 할 수 있다는 것을 이해해야합니다. 물론 앱을 Google Play에 게시한다는 목표를 달성 할 수 없습니다.

전반적으로 숨겨진 API를 사용하고있는 것으로 보입니다. 이 목표를 달성하기 위해서는 다른 방법을 고려해야합니다. 아마도 APN을 프로그래밍 방식으로 변경할 수는 없지만 확실하지 않습니다.