android grantPermission() error && java.lang.IllegalStateException: - exception

Helo!
This is one another self answered question by me. I hope you get a little help.
So.. This is one permission error about the sdk23 or higher sdk devices. 'Cause the permission accepts are changed! Not the all permissions are can accepted at the installation moment. This change says that:
The user have the choice to accept or deny one permission while the app is running.Here are the automaticaly granted permissions:
android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_ACCOUNTS
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT
So we don't have any other things to do just ask the user what he wanna do.. This is the fund set up. Let's get coding. The code in the answer section! But do not forget to write permissions in the Manifest too for the older android sdk-s!!!

So here is the code:
create new int whith dont exist value. Examp: if you have one int with value 1, this int couldn't be 1.. Then this int will be something else.
int YOUR_PERMISSION_REQUEST = 1212;
&& In the onCreate method
//If the sdk level equals or higher than 23.
if (Build.VERSION.SDK_INT >= 23){
//The permission we wanna accept
int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE);
//If is not accepted for this app ask the user he wanna accept it or not.
if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[] {Manifest.permission.READ_EXTERNAL_STORAGE},
YOUR_PERMISSION_REQUEST);
}
So you can asks the users to accept one permission. If you wanna ask about other permission you change the READ_EXTERNAL_STORAGE permissions in the code to your permission. Good Luck. Hope I can help you.

Related

SetTag() on calendar event results in Action not allowed error for some users

I am facing the same issue as discussed here, however I checked all the needed permissions, and I can not reproduce this issue on my test system, and only some users have this issue on the production system.
I have one use case on production where this happens (but it happens on many users) with the following setup:
UserA has full permission to the calendar of UserB (manage and share)
UserA creates an event in the calendar of UserB
UserA uses then a calendar addon to set the tag -> which results in an error.
This is the code part where the tag is set:
const additionalInfo: AdditionalInfo = {
info: {
moreinfo: {
r: "somestring",
m: {
st: event.getStartTime().toJSON(),
et: event.getEndTime().toJSON(),
ro: ['ddd','ddsd'],
t: event.getTitle(),
h: generateHash(users.map(e => e.getEmail())),
c: event.getOriginalCalendarId()
}
}
},
}
event.setTag("Info", JSON.stringify(additionalInfo)) // Action not allowed
I also logged the tag and set the complete shared property on a test event without any problems. The length of the complete shared properties is around 600 characters so this should also not be a problem since I tested the max length which is apparently 1024.
I really have no clue what the issue is here....

Sitecore 9: Non Admin members are unable to publish items when Publishing.CheckSecurity is set to True

Current Scenario(Sitecore 9) User is not able to publish any item to any publishing target, not even on the web database. We face this issue when we set Publishing.CheckSecurity to true in Sitecore.config.
There is no workflow on the item, User has all (Read, write, delete, create) access on the item.
I dug into Sitecore.Kernel Dll and found the difference
public bool CanPublish(ID itemId, User user, ref string explanation)
{
Assert.ArgumentNotNull(itemId, “itemId”);
Assert.ArgumentNotNull(user, “user”);
Assert.ArgumentNotNull(explanation, “explanation”);
if (!Settings.Publishing.CheckSecurity)
{
return true;
}
if (!this.CanPublishLanguage(itemId, user, ref explanation))
{
return false;
}
Item sourceItem = this.GetSourceItem(itemId);
if (sourceItem == null)
{
return this.CanPublishDeletion(itemId, user, ref explanation);
}
return this.CanPublishUpdate(sourceItem, user, ref explanation);
}
Earlier (Sitecore 8.1) “CanPublishLanguage” was not there. I have given all the access on language but still, my items are getting skipped while publishing. The function is returning false.
If I make this setting as false then it is working fine.
Please suggest if I am missing some more config change for this.
This issue is with Sitecore 9 and got fixed in Sitecore 9.0 Update 2.
Raised this issue with Sitecore and got the resolution for this.
The reported issue looks like one that has been fixed in the Sitecore 9.0 Update-2:
https://dev.sitecore.net/Downloads/Sitecore%20Experience%20Platform/90/Sitecore%20Experience%20Platform%2090%20Update2/Release%20Notes
When the Publishing.CheckSecurity setting is set to true, non-admin users are not able to publish content items even when they have all the appropriate security permissions 206940
To fix the issue we suggest you upgrade your Sitecore solution to the Sitecore XP 9.0 Update 2 (rev. 180604).
In case it is not possible, you can try the following patch: https://sitecore.box.com/s/swae96e2hhgrbid3keccmvzr4e8kbvr7
To install the patch follow the instructions from the readme file inside the archive.

RXSwift eventlistener

I´m kind of new to the reactive pattern and now I have my first bigger question.
I have done a few asychronous requests in the reactive way. But what I wan´t to do now is a "Eventlistener".
I have a Session object, at the moment I have an SessionEventListener protocol. The Session has a list of listeners and informs all of them about a successfull login and an logout. This Listeners can subscribe and unsubscribe. This thing I want to create reactive now.
How would you do that?
My Idea is to define a BehaviourSubject:
public let loginEventBehaviourSubject = BehaviorSubject(value: true)
now I can send onNext true if the session logged in, and false if it was logged out:
loginEventBehaviourSubject.onNext(true) // on login
loginEventBehaviourSubject.onNext(false) // on logout
And my "listeners" can subscribe to it.
But I would prefere to have subjects for every event:
public let loginEventBehaviourSubject = BehaviorSubject(value: )
public let logoutEventBehaviourSubject = BehaviorSubject(value: )
But then I wouldn´t need the bool. Can I make a kind of "empty" Subject, that only fire "events" without submitting really data.
And then my last question:
Why do I have to add an instance to the initializer of the Subject. Why can´t I create it like: BehaviourSubject<Bool>()?
You need to give an initial value to behavior subject because of it's API. Indeed, it defines BehaviorSubject<T>.value() method, which returns a T. And it would not make sense to call value without a proper initial value. In the presented case, I think PublishSubject is a better representation of the task at hand. You can find more documentation on the available kinds of subjects on the reactivex website.
If you are only interested in the .next event of your subjects, you can do let loginSubject = PublishSubject<Void>() (using behavior subject, you could have written BehaviorSubject<Void>(value: ())) and will the be able to call loginSubject.onNext().
Note though that using any subject is often an anti-pattern. Indeed, subject are most of the time intended to bridge from the imperative to the reactive world and you can very often create things like loginEventObservable as a combination of other observables. For more information on this, I recommend reading To Use Subject Or Not To Use Subject?. It is written using the .Net implementation of Rx, but the theory stays the same.

Auto keyboard by using SendMessage

int VK_F_DOWN = GetVirtualKey('F', 0);
int VK_F_UP = GetVirtualKey('F', 1);
HWND hWnd = FindWindow(NULL,L"Calculator.exe");
SendMessage(hWnd, WM_KEYDOWN, toascii('F'), VK_F_DOWN);
SendMessage(hWnd, WM_KEYUP, toascii('F'), VK_F_UP);
It doesn't work on the Calculator.exe,however it can work on my visual studio when I change hWnd to HWND(0xFFFF).
And I also already got a non-zero hWnd. What am I missing here? Like authority or something?
Sounds like User Interface Privilege Isolation. As the Wikipedia article explains, you can request the access you want in your application manifest.
That said, you should be using SendInput rather than SendMessage. See one of Raymond Chen's blog entries on that point.

DbContext.ChangeTracker, DbContext.Entry() inconsistencies

Under the debugger I have a case where DbContext.ChangeTracker.Entry(e) returns an entry with a State of Detached. When I enumerate the results of DbContext.ChangeTracker.Entries() and the entries of the underlying ObjectContext when looking for e, I find an entry with a State of Unchanged (expected).
What is going on?
Here are some additional details:
using POCO entities.
change Tracking is on
proxy creation is off
lazy loading is off
problem does not occur when saving an entity for the first time (e.g. adding to context); occurs when getting old entity into context then trying to make changes to it. This is an aggregate root with many "reference" entities that aren't supposed to change
Equals is overridden on the entities and IEquatable<T> is implemented. That code is generated by T4.
I am using a generic repository implementation that is declaratively configured to generate rules for saving (e.g. whether entities should be added, attached/modified, attached/unchanged. It seems to be doing this in the right order. For example the aggregate root is added/attached last because attaching it first brings in other entities in a modified state (adding those first as unchanged prevents this).
(Answered in a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
I have "solved" the problem, but I still want to know what's going on, because my solution doesn't do anything to address the root cause. My "solution" looks for an entity in the change tracker (I have also looked via the context.Entry() and context.Set().Local -- when I do it with this code (I did it as a loop instead of LINQ so I could set breakpoints), it works:
private DbEntityEntry GetChangeTrackedEntry(IEntity mine, Type type)
{
foreach (var en in context.ChangeTracker.Entries())
{
if (en.Entity.GetType() != type)
continue;
if (((IEntity)en.Entity).Id != mine.Id)
continue;
return en;
}
return null;
}
When I attempt to lookup an entity (via change tracker, the set, etc.) via using mine directly, that's when I end up with a detached case.
I thought perhaps there were cases of EF using ReferenceEquals but #Ladislav's comment may indicate something wrong with Equals implementation.
If anyone has a further explanation they can edit that into this community wiki answer.