Courts have been interpreting the second amendment as it is applied to "safe storage" laws with a significant amount of legislative discretion. The issue here is that the Heller Decision found against D.C. safe storage statute- which forced the gun to be unloaded and dissasembled/locked up at almost all times within the home. Most safe storage statutes (IIRC including MA) use wording that is similair to "all guns must be secured when out of the owners immediate control". Now, what defines "immediate control" is open to debate, but the key fact is that such a statute allows you to keep a loaded firearm that is "ready to go" for the purpose of self defense. For example, in MA, you could walk around your home with a loaded 9mm handgun strapped to your hip- its fully legal, but in D.C.'s case such an act (irregardless of the legality of the firearm itself) would be illegal
I hope this provides some helpful insight
On edit: I think more of these types of laws will be found constitutional. To explain how Heller is being applied (as simply as possible, but i might add this does not do the debate justice) in the very same way Griswald V CT was (the case that struck down the contraception ban in CT). That is, it is being used to knock down laws that are "outliers" or "outside public consensus".