0

So basically I'm building an app and one of those features is to be able to sync up the date time with a value from a database.

(The application is signed - and from what I have read, the SET_TIME permission is "signatureOrSystem" locked, therefore we should be able to access it)

I've got the permission required inside of the AndroidManifest.xml

```

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.SET_TIME" />
<uses-permission android:name="android.permission.SET_TIME_ZONE" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />

```

And I've also got permission request code sorted (I may be using the wrong request method/class)

```

  if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.SetTime) != Permission.Granted)
  {
    if (ActivityCompat.ShouldShowRequestPermissionRationale(this, Manifest.Permission.SetTime))
      ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.SetTime }, 0);
    else
      ActivityCompat.RequestPermissions(this, new string[] { Manifest.Permission.SetTime }, 0);
  }

```

I've also added some code to ensure that the signature is attached to the debugger

```
  var _context = Android.App.Application.Context;
  foreach (Android.Content.PM.Signature signature in _context.PackageManager.GetPackageInfo(_context.PackageName, PackageInfoFlags.Signatures).Signatures)
  {
    using (SHA1Managed sha1 = new SHA1Managed())
    {
      var hash = sha1.ComputeHash(signature.ToByteArray());
      var sb = new StringBuilder(hash.Length * 2);
      foreach (byte b in hash)
      {
        sb.Append(b.ToString("X2"));
      }

      System.Diagnostics.Debug.WriteLine(sb.ToString());
    }
  }
```

However, I don't seem to be given access to the permission.

Which one signature comes up, which is what is expected. However, upon running through my set time button code:

```

  Button _btn = FindViewById<Button>(Resource.Id.btnSetTime);
  _btn.Click += (sender, e) =>
  { 
    DateTime _time = DateTime.Now;
    Calendar c = Calendar.GetInstance(new Java.Util.Locale("it-IT"));
    c.Set(_time.Year, _time.Month, _time.Day, _time.Hour + 1, _time.Minute, _time.Second);

    AlarmManager am = (AlarmManager)this.GetSystemService(AlarmService);
    am.SetTime(c.TimeInMillis);
  };

```

I am getting the error: Java.Lang.SecurityException: 'setTime: Neither user 10517 nor current process has android.permission.SET_TIME.'

I am wondering if anyone knows why this may be happening and any way to fix this? Or if its possible at all?

Android Version: 9.0 SDK Version: 28

Skyhighjinks
  • 162
  • 1
  • 1
  • 10
  • If you are creating and signing the Android image, yes, you can use the same cert to sign an app to obtain the SET_TIME perm. But I'm assuming you are not doing that and are just creating a 3rd party app, so no, your app can not change the OS' date/time (that would be a huge security hole) – SushiHangover Aug 04 '21 at 17:45
  • @Skyhighjinks it is by design that applications can not change the time. There are many subtle aspects of security that can rely on the current time, such as certificate expiration, license management, etc. We do not want to allow third party applications to globally disrupt the system in this way. More detailed info you can take a look [Setting system time of ROOTED phone](https://stackoverflow.com/questions/8739074/setting-system-time-of-rooted-phone) – Cherry Bu - MSFT Aug 05 '21 at 02:17

0 Answers0